BradleyBrokers Posted February 14, 2008 Share Posted February 14, 2008 If I have arrays that look like this: <Code> <?PHP $intro[0]="dog has paws"; $intro[1]="cat has tail"; $intro[2]="Fish has fin"; $intro[3]="bird has wing"; $body[0]="red is hot"; $body[1]="black is dark"; $body[2]="green is good"; $body[3]="yellow is mellow"; $final[0]="hand grabs"; $final[1]="foot walks"; $final[2]="arm rests"; $final[3]="knee bends"; ?> </code> 1) How do I express and echo, "Fish has fin, green is good, arm rests" i.e. the [2] of $intro, $body, $final ? 2) How do I display these arrays together in array groupings? i.e. how do I create the correct array of arrays: First array, $intro[0] $body[0] $final[0] second array, $intro[1] $body[1] $final[1] third array, $intro[2] $body[2] $final[2] Link to comment https://forums.phpfreaks.com/topic/90998-displaying-arrays/ Share on other sites More sharing options...
kenrbnsn Posted February 14, 2008 Share Posted February 14, 2008 1) One way: <?php for ($i=0;$i<3;$i++) { $tmp = array(); $tmp[] = $intro[$i]; $tmp[] = $body[$i]; $tmp[] = $final[$i]; echo implode(', ',$tmp) . "<br>\n"; }?> 2) <?php $first_array = array($intro[0],$body[0],$final[0]); $second_array = array($intro[1],$body[1],$final[1]); $third_array = array($intro[2],$body[2],$final[2]); ?> Ken Link to comment https://forums.phpfreaks.com/topic/90998-displaying-arrays/#findComment-466411 Share on other sites More sharing options...
teng84 Posted February 14, 2008 Share Posted February 14, 2008 //multidimensional array $x[] = array("dog has paws","red is hot","hand grabs"); $x[] = array("cat has tail","black is dark","foot walks"); foreach($x as $val){ foreach($val as $val2){ echo $val2; } } Link to comment https://forums.phpfreaks.com/topic/90998-displaying-arrays/#findComment-466412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.