I want to print a array where I don't know the dimension of the array value.
Now the fact is when I use echo '<pre>'
and then print_r($array)
it will show the Key
and value
with <br>
display.
But I want to display only the value and not the key of the array. That $array
may contain multi-dimensional array value or single value or both.
You have to use recursive function:
$array_list = array('a',array(array('b','c','d'),'e')); // Your unknown array
print_array($array_list);
function print_array($array_list){
foreach($array_list as $item){
if(is_array($item)){
print_array($item);
}else{
echo $item.'<br>';
}
}
}
try this Recursive
function
function print_array($array, $space="")
{
foreach($array as $key=>$val)
{
if(is_array($val))
{
$space_new = $space." ";
print_array($val, $space_new);
}
else
{
echo $space." ".$val." ".PHP_EOL;
}
}
}
See Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With