I have a multidimensional array.
array_values()
only gets the first level. While I need to get all the values, or in other words, I need a function to convert a multidimensional array into a one-dimensional array.
My function looks like this:
`$array = array(
[0] => array(1=>"first value", 2=>"second value"),
[1] => array(),`
While I need to convert it into an array like this:
`$array = array("first value", "second value");`
Using user defined function “array_values_recursive” we can combine the multi dimensional array values into single dimensional array.
The function is
function array_values_recursive($ary) {
$lst = array();
foreach( array_keys($ary) as $k ) {
$v = $ary[$k];
if (is_scalar($v)) {
$lst[] = $v;
} elseif (is_array($v)) {
$lst = array_merge($lst,array_values_recursive($v));
}
}
return $lst;
}
This should work.
$array = array();
foreach($array1 as $key=>$value)
{
$array = array_merge($array,array_values($value));
}