Apply $callback to each element of an $array.
Passes to $callback item value as 1'st and item key as 2'nd parameter

@param array $array
@param callable $callback
@param bool $recursive

@return bool
424026
public static function walk(array $array, callable $callback, bool $recursive = false): bool
    {
        return $recursive ? \array_walk_recursive($array, $callback) : \array_walk($array, $callback);
    }
1001190
public static function toArray($data, $recursive = false)
    {
        // Ensure the input data is an array.
        if (\is_object($data)) {
            if ($data instanceof \Traversable) {
                $data = iterator_to_array($data);
            } elseif (method_exists($data, 'toArray')) {
                $data = $data->toArray();
            }
        } else {
            $data = (array)$data;
        }

        if ($recursive) {
            foreach ($data as &$value) {
                if (\is_array($value) || \is_object($value)) {
                    $value = static::toArray($value, $recursive);
                }
            }
        }

        return $data;
    }
356
public static function compact($array, $reindex = false)
    {
        $out = array_filter($array, function ($item) {
            return false !== (bool)$item;
        });

        return false !== $reindex && self::isList($out) ? array_values($out) : $out;
    }
320103
public static function filterArray(array $array, Closure $callback)
    {
        foreach ($array as $index => $collection) {
            $array[$index] = call_user_func($callback, $collection);
        }

        return $array;
    }
440687
public static function convert($object, $recursive = false)
    {
        if ($object instanceof \Traversable) {
            $array = iterator_to_array($object);
        } elseif (method_exists($object, 'toArray')) {
            $array = $object->toArray();
        } elseif (method_exists($object, 'asArray')) {
            $array = $object->toArray();
        } elseif (method_exists($object, 'as_array')) {
            $array = $object->toArray();
        } elseif (method_exists($object, 'getArrayCopy')) {
            $array = $object->toArray();
        } elseif (is_object($object)) {
            $array = get_object_vars($object);
        } else {
            $array = (array) $object;
        }

        if (!$recursive) {
            return $array;
        }

        $data = [];
        foreach ($array as $key => $value) {
            $data[$key] = is_object($value)
                ? self::convert($value, $recursive)
                : $value;
        }

        return $data;
    }
1020059
public function __toArray($recursive = false)
    {
        if ($recursive) {
            return Util::convertEasyPostObjectToArray($this->_values);
        }

        return $this->_values;
    }
1105934
public static function toArray($data, bool $recursive = false)
    {
        $arr = [];

        // Ensure the input data is an array.
        if (\is_object($data)) {
            if ($data instanceof \Traversable) {
                $arr = \iterator_to_array($data);
            } elseif (\method_exists($data, 'toArray')) {
                $arr = $data->toArray();
            }
        } else {
            $arr = (array)$data;
        }

        if ($recursive) {
            foreach ($arr as $key => $value) {
                if (\is_array($value) || \is_object($value)) {
                    $arr[$key] = static::toArray($value, $recursive);
                }
            }
        }

        return $arr;
    }
1035391
public static function toArray($object, $recursive = true)
    {
        $array = [];

        if ($object instanceof BaseObject) {
            return $object->toArray($recursive);
        }

        foreach ($object as $key => $value) {
            if ($value instanceof BaseObject) {
                $newValue = $value->toArray($recursive);
            } else {
                $newValue = (is_array($value) || is_object($value)) && $recursive ? self::toArray($value) : $value;
            }

            $array[$key] = $newValue;
        }

        return $array;
    }
521850
public function getKeys($recursive = TRUE) {
    $keys = new NodeCollection();
    $index = 0;
    foreach ($this->elements->getItems() as $element) {
      if ($element instanceof ArrayPairNode) {
        $keys->add($element->getKey());
        $value = $element->getValue();
      }
      else {
        $keys->add(Token::integer($index++));
        $value = $element;
      }

      if ($recursive && $value instanceof ArrayNode) {
        $keys->add($value->getKeys($recursive));
      }
    }
    return $keys;
  }
1112824
public static function mergeSort(&$array, \Closure $callback)
    {
        // Arrays of size < 2 require no action.
        if (count($array) < 2) {
            return;
        }

        // Split the array in half
        $halfway = count($array) / 2;
        $array1 = array_slice($array, 0, $halfway);
        $array2 = array_slice($array, $halfway);

        // Recurse to sort the two halves
        self::mergeSort($array1, $callback);
        self::mergeSort($array2, $callback);

        // If all of $array1 is <= all of $array2, just append them.
        if (call_user_func($callback, end($array1), $array2[0]) < 1) {
            $array = array_merge($array1, $array2);

            return;
        }

        // Merge the two sorted arrays into a single sorted array
        $array = [];
        $ptr1 = $ptr2 = 0;

        while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
            if ($callback($array1[$ptr1], $array2[$ptr2]) < 1) {
                $array[] = $array1[$ptr1++];
            } else {
                $array[] = $array2[$ptr2++];
            }
        }
        // Merge the remainder
        while ($ptr1 < count($array1)) {
            $array[] = $array1[$ptr1++];
        }

        while ($ptr2 < count($array2)) {
            $array[] = $array2[$ptr2++];
        }
    }
1286609
public function replace($items = array(), $recursive = true)
	{
		$items = (array) $items;

		if ($recursive) {
			$this->data = array_replace_recursive($this->data, $items);
		} else {
			$this->data = $items;
		}
	}
33518
public function each($items, callable $callback = null)
    {
        if ($items instanceof \Traversable) {
            $items = iterator_to_array($items);
        }

        $total = count($items);
        if (!$total) {
            return;
        }
        $this->total($total);

        foreach ($items as $key => $item) {
            if ($callback) {
                $label = $callback($item, $key);
            } else {
                $label = null;
            }

            $this->advance(1, $label);
        }
    }
627536
public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self
    {
        if ($recursive === true) {
            $result = \array_merge_recursive($this->getArray(), $array);
        } else {
            $result = \array_merge($this->getArray(), $array);
        }

        return static::create(
            $result,
            $this->iteratorClass,
            false
        );
    }
802004
private static function array_recursive(&$array, $function, $apply_to_keys_also = false) {
		foreach ( $array as $key => $value ) {
			if (is_array ( $value )) {
				self::array_recursive ( $array [$key], $function, $apply_to_keys_also );
			} else {
				$array [$key] = $function ( $value );
			}

			if ($apply_to_keys_also && is_string ( $key )) {
				$new_key = $function ( $key );
				if ($new_key != $key) {
					$array [$new_key] = $array [$key];
					unset ( $array [$key] );
				}
			}
		}
	}
918850
function(recursive, callback) {
		var i, l, node,
			dict = {},
			self = this;

		$.each(NODE_ATTRS, function(i, a){
			if(self[a] || self[a] === false){
				dict[a] = self[a];
			}
		});
		if(!$.isEmptyObject(this.data)){
			dict.data = $.extend({}, this.data);
			if($.isEmptyObject(dict.data)){
				delete dict.data;
			}
		}
		if( callback ){
			callback(dict);
		}
		if( recursive ) {
			if(this.hasChildren()){
				dict.children = [];
				for(i=0, l=this.children.length; i<l; i++ ){
					node = this.children[i];
					if( !node.isStatusNode() ){
						dict.children.push(node.toDict(true, callback));
					}
				}
			}else{
//                dict.children = null;
			}
		}
		return dict;
	}
13394
public function every(callable $callback)
    {
        $array = $this->getArrayCopy();
        foreach ($array as $key => $value) {
            if ($callback($value, $key, $array) === false) {
                return false;
            }
        }

        return true;
    }
1003556
public static function filterRecursive($array, $callback = null)
	{
		foreach ($array as &$value)
		{
			if (is_array($value))
			{
				$value = $callback === null ? static::filterRecursive($value) : static::filterRecursive(
																					  $value,
																						  $callback
				);
			}
		}

		return $callback === null ? array_filter($array) : array_filter($array, $callback);
	}