本文整理匯總了PHP中Toolbox::array_flatten方法的典型用法代碼示例。如果您正苦於以下問題:PHP Toolbox::array_flatten方法的具體用法?PHP Toolbox::array_flatten怎麽用?PHP Toolbox::array_flatten使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Toolbox
的用法示例。
在下文中一共展示了Toolbox::array_flatten方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array_flatten
/**
* Reduce a nested array to a single level array
*
* <p>
* Reduce a nested array (associative or simple) to a single level array. Simple arrays will be unwrapped and stacked at the same position. In associative array, the less deep key is kept.
* <pre><code>Toolbox::array_flatten(array(array(1,2),array(3,4))); // will output array(1,2,3,4)
* Toolbox::array_flatten(array(1 => 1,2 => array(1 => "A",3 => 3))); // will output array(1 => 1, 3 => 3)
* </code></pre>
*
* @param mixed[] $array The multilevel array to flatten
*
* @return mixed[] Return a single level array
*/
public static final function array_flatten($array)
{
$return = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$return = array_merge(Toolbox::array_flatten($value), $return);
} else {
$return[$key] = $value;
}
}
return $return;
}