Exemple #1
0
 /**
  * Get the values of a collection.
  *
  * @param array|Traversable|AssociativeInterface|SequenceInterface $collection
  *
  * @return array An array containing the values of $collection.
  */
 public static function values($collection)
 {
     if ($collection instanceof AssociativeInterface) {
         return $collection->values();
     } elseif ($collection instanceof SequenceInterface) {
         return $collection->elements();
     } elseif (is_array($collection)) {
         return array_values($collection);
     }
     $values = array();
     foreach ($collection as $value) {
         $values[] = $value;
     }
     return $values;
 }
Exemple #2
0
 /**
  * Add the elements from one or more other collections to this collection.
  *
  * Any existing keys are overwritten from left to right.
  *
  * @param AssociativeInterface $collection     The collection to merge.
  * @param AssociativeInterface $additional,... Additional collections to merge.
  */
 public function mergeInPlace(AssociativeInterface $collection)
 {
     foreach (func_get_args() as $collection) {
         foreach ($collection->elements() as $element) {
             list($key, $value) = $element;
             $this->set($key, $value);
         }
     }
 }