How can I display this multidimensional array -
How can I display this multidimensional array -
i have created multidimentional array called 'orders'. have no thought how can display visitor in readable way. how can display in table or something?
how display it:
<table> <tr> <td>cake</td> <td>ingredient1</td> <td>ingredient2</td> <td>ingredient3</td> <td>ingredient</td> </tr> <tr> <td>chocolate cookie</td> <td>5</td> </tr> <!-- , go on... --> </table>
this array:
array(5) { [0]=> array(2) { [0]=> string(4) "cake" [1]=> array(5) { [0]=> string(11) "ingredient1" [1]=> string(11) "ingredient2" [2]=> string(11) "ingredient3" [3]=> string(11) "ingredient4" [4]=> string(11) "ingredient5" } } [1]=> array(2) { [0]=> string(16) "chocolate cookie" [1]=> string(1) "5" } [2]=> array(2) { [0]=> string(15) "chocolate cakes" [1]=> string() "10" } [3]=> array(2) { [0]=> string(6) "cookie" [1]=> array(3) { [0]=> string(11) "ingredient1" [1]=> string(11) "ingredient2" [2]=> string(11) "ingredient3" } } }
you can in php next method
$array=array(); $array[0]=array(0 => 'cake',1 =>array(0 => 'ingredient1',1 => 'ingredient1',2 => 'ingredient1')); $array[1]=array(0 => 'pizza',1 =>array(0 => 'ingredient11',1 => 'ingredient12',2 => 'ingredient13')); $html='<table>'; foreach($array $arr){ $newarray=""; //intialization $html.='<tr>'; $html.='<td>'.$arr[0].'</td>'; $newarrays=$arr[1]; foreach($newarrays $newarr){ $html.='<td>'.$newarr.'</td>'; } $html.='</tr>'; } $html.="</table>"; echo $html;
please check , allow me know if want in same way
thanks
arrays multidimensional-array
Comments
Post a Comment