moon 111 Posted March 29, 2008 Share Posted March 29, 2008 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]; } Quote Link to comment https://forums.phpfreaks.com/topic/98508-multidimensional-foreach/ Share on other sites More sharing options...
wildteen88 Posted March 29, 2008 Share Posted March 29, 2008 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/98508-multidimensional-foreach/#findComment-504113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.