In short, you can use a recursive function for what you want to achieve:
function print_no_keys(array $array){ foreach($array as $value){ if(is_array($value)){ print_no_keys($value); } else { echo $value, PHP_EOL; } } }
Another way is to use array_walk_recursive() .
If you want to use indentation, try the following:
function print_no_keys(array $array, $indentSize = 4, $level = 0){ $indent = $level ? str_repeat(" ", $indentSize * $level) : ''; foreach($array as $value){ if(is_array($value)){ print_no_keys($value, $indentSize, $level + 1); } else { echo $indent, print_r($value, true), PHP_EOL; } } }
Example:
<?php header('Content-Type: text/plain; charset=utf-8'); $a = [1, [ 2, 3 ], 4, new stdClass]; function print_no_keys(array $array, $indentSize = 4, $level = 0){ $indent = $level ? str_repeat(" ", $indentSize) : ''; foreach($array as $value){ if(is_array($value)){ print_no_keys($value, $indentSize, $level + 1); } else { echo $indent, print_r($value, true), PHP_EOL; } } } print_no_keys($a); ?>
Conclusion:
1 2 3 4 stdClass Object ( )
source share