Jump to content

Displaying arrays


BradleyBrokers

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.