0

<?php $mix = array("Cars"=> array("Alto","Scooty"),"Fruit"=>array("orange","Mango")); foreach ($mix as $s){ echo "$s"; }

Where is my error

30th Jan 2020, 2:49 PM
Yaro Ka Yar
Yaro Ka Yar - avatar
1 Antwort
+ 4
When you run this code, you get : in log : PHP Notice: Array to string conversion and the output is : ArrayArray The problem is that $s contains again array. It depends what you want to achieve. You can use var_dump($mix) or print_r($mix) to see the content of the array with additional info or if you just want to print the content of the inner arrays, you can use another loop. For example: foreach ($mix as $s){ foreach($s as $x) { echo("$x "); } echo("<br/>"); }
30th Jan 2020, 3:08 PM
Michal Straka
Michal Straka - avatar