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. 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 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]; } } 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. Link to comment https://forums.phpfreaks.com/topic/242508-logic-problem/#findComment-1245498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.