xkklxl Posted July 21, 2011 Share Posted July 21, 2011 Say, I have a multidimensional array named Array. Array[0] = "apple", "banana", "cantaloupe", "date" Array[1] = "asparagus", "broccoli", "carrot", "dandelion" How would I make a new multidimensional array from this multidimensional array with all the 0's from say "apple" and "asparagus?" Like I'd like my new array to look like this: Array[0] = "apple", "asparagus" Array[1] = "banana", "broccoli" Array[2] = "cantaloupe", "carrot" Array[3] = "date", "dandelion" My brain seems dead right now. I can't think of a way to do it. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/242508-logic-problem/ Share on other sites More sharing options...
Maknib Posted July 21, 2011 Share Posted July 21, 2011 you just broke my brain! too late in the arvo for this. hehe Quote Link to comment https://forums.phpfreaks.com/topic/242508-logic-problem/#findComment-1245489 Share on other sites More sharing options...
abdfahim Posted July 21, 2011 Share Posted July 21, 2011 If your source array has same number elements in each sub-array, otherwise it will need little tweaking on this code $sourcearr = array( array("apple", "banana", "cantaloupe", "date"), array("asparagus", "broccoli", "carrot", "dandelion") ); for($i=0;$i<count($sourcearr[0]);$i++){ for($j=0;$j<count($sourcearr);$j++){ $targtarr[$i][]=$sourcearr[$j][$i]; } } Quote Link to comment https://forums.phpfreaks.com/topic/242508-logic-problem/#findComment-1245491 Share on other sites More sharing options...
xkklxl Posted July 21, 2011 Author Share Posted July 21, 2011 Nailed it. Thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/242508-logic-problem/#findComment-1245498 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.