Jump to content

Multidimensional foreach


moon 111

Recommended Posts

I have a multidimensional array. It is organized like so:

 

$file = array(array("title1", "message1"), array("title2", "message2"));

 

etc...

 

I'm trying to move the "title" part and the "message" part into two different arrays so that I have

 

$title = array("title1", "title2");
$message = array("message1", "message2");

 

Would this work?

 

foreach($file as $value)
    {
      $title[] = $value[0];
      $message[] = $value[1];
    }

Link to comment
https://forums.phpfreaks.com/topic/98508-multidimensional-foreach/
Share on other sites

Yes that should work fine. To see if the the $title and $message arrays are populated properly place the following code after the foreach

 

echo '$title <pre>' . print_r($title, true) . '</pre>';
echo '$message <pre>' . print_r($message , true) . '</pre>';

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.