I have a multidimensional array and I was given a foreach loop, but don't know how to echo out all the values without using print_r. I do get a result if I echo $array[0][0]; outside the foreach loop, for the first result.
I had seen other examples but nothing to show the results other than print_r and they tend to do only a single array, not a multidimensional array.
I had seen this foreach loop that seems like it would work, but I only get errors if I try to do echo $new_array inside the foreach loop. How can I use this for something like this situation?
foreach($array as $key=>$val) {
$new_array[] = $val['key'];
}
array results from print_r
[0] => Array
(
[0] => 2
[audit_inspectionID] => 10
[1] => 2015-08-12
[created] => 2015-08-12
[2] => 2016-08-11 16:26:22
[modified] => 2016-08-11 16:26:22
[class_answer] => Array
(
[0] => Needs Improvement
[1] => Need To Correct
[2] => Needs Immediate Action
)
)
[1] => Array
(
[0] => 12
[audit_inspectionID] => 12
[1] => 2016-08-12
[created] => 2016-08-12
[2] => 2016-08-11 16:26:22
[modified] => 2016-08-11 16:26:22
[class_answer] => Array
(
[0] => Needs Improvement
[1] => Need To Correct
[2] => Needs Immediate Action
)
)
$new_array[]=$val['key']foreach ($data as $d) foreach ($d as $k=>$v) echo $k, '->', $v, PHP_EOL;PHP_EOLwhen you want to start a new line on a plain terminal or when writing to a file. When writing to a web page, use<br>.