Skip to main content

Get Array Values with PHP Recursively.

<?php

/**
 * Get Array Values PHP Recursively
 *
 * https://davidwalsh.name/get-array-values-with-php-recursively
 *
 * @param array $array The source array.
 * @return array The flattened array values.
 */
function array_values_recursive($array)
{
    $flat = array();

    foreach ($array as $value) {
        if (is_array($value)) {
            $flat = array_merge($flat, array_values_recursive($value));
        } else {
            $flat[] = $value;
        }
    }

    return $flat;
}