public static function addValue(
    $subject, $property, $value, $options=array()) {
    self::setdefaults($options, array(
      'allowDuplicate' => true,
      'propertyIsArray' => false));

    if(is_array($value)) {
      if(count($value) === 0 && $options['propertyIsArray'] &&
        !property_exists($subject, $property)) {
        $subject->{$property} = array();
      }
      foreach($value as $v) {
        self::addValue($subject, $property, $v, $options);
      }
    } else if(property_exists($subject, $property)) {
      // check if subject already has value if duplicates not allowed
      $has_value = (!$options['allowDuplicate'] &&
        self::hasValue($subject, $property, $value));

      // make property an array if value not present or always an array
      if(!is_array($subject->{$property}) &&
        (!$has_value || $options['propertyIsArray'])) {
        $subject->{$property} = array($subject->{$property});
      }

      // add new value
      if(!$has_value) {
        $subject->{$property}[] = $value;
      }
    } else {
      // add new value as set or single value
      $subject->{$property} = ($options['propertyIsArray'] ?
        array($value) : $value);
    }
  }
public static function addValue(
    $subject, $property, $value, $options=array()) {
    self::setdefaults($options, array(
      'allowDuplicate' => true,
      'propertyIsArray' => false));

    if(is_array($value)) {
      if(count($value) === 0 && $options['propertyIsArray'] &&
        !property_exists($subject, $property)) {
        $subject->{$property} = array();
      }
      foreach($value as $v) {
        self::addValue($subject, $property, $v, $options);
      }
    } else if(property_exists($subject, $property)) {
      // check if subject already has value if duplicates not allowed
      $has_value = (!$options['allowDuplicate'] &&
        self::hasValue($subject, $property, $value));

      // make property an array if value not present or always an array
      if(!is_array($subject->{$property}) &&
        (!$has_value || $options['propertyIsArray'])) {
        $subject->{$property} = array($subject->{$property});
      }

      // add new value
      if(!$has_value) {
        $subject->{$property}[] = $value;
      }
    } else {
      // add new value as set or single value
      $subject->{$property} = ($options['propertyIsArray'] ?
        array($value) : $value);
    }
  }
public static function addValue ( $ subject , $ property , $ value , $ options = array ( ) ) { self :: setdefaults ( $ options , array ( 'allowDuplicate' => true , 'propertyIsArray' => false ) ) ; if ( is_array ( $ value ) ) { if ( count ( $ value ) === 0 && $ options [ 'propertyIsArray' ] && ! property_exists ( $ subject , $ property ) ) { $ subject -> { $ property } = array ( ) ; } foreach ( $ value as $ v ) { self :: addValue ( $ subject , $ property , $ v , $ options ) ; } } else if ( property_exists ( $ subject , $ property ) ) { // check if subject already has value if duplicates not allowed $ has_value = ( ! $ options [ 'allowDuplicate' ] && self :: hasValue ( $ subject , $ property , $ value ) ) ; // make property an array if value not present or always an array if ( ! is_array ( $ subject -> { $ property } ) && ( ! $ has_value || $ options [ 'propertyIsArray' ] ) ) { $ subject -> { $ property } = array ( $ subject -> { $ property } ) ; } // add new value if ( ! $ has_value ) { $ subject -> { $ property } [ ] = $ value ; } } else { // add new value as set or single value $ subject -> { $ property } = ( $ options [ 'propertyIsArray' ] ? array ( $ value ) : $ value ) ; } }
Adds a value to a subject. If the value is an array, all values in the
array will be added.

Note: If the value is a subject that already exists as a property of the
given subject, this method makes no attempt to deeply merge properties.
Instead, the value will not be added.

@param stdClass $subject the subject to add the value to.
@param string $property the property that relates the value to the subject.
@param mixed $value the value to add.
@param assoc [$options] the options to use:
[propertyIsArray] true if the property is always an array, false
if not (default: false).
[allowDuplicate] true to allow duplicates, false not to (uses a
simple shallow comparison of subject ID or value)
(default: true).
Adds a value to a subject . If the value is an array all values in the array will be added .