Jump to content

Logic problem...


xkklxl

Recommended Posts

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

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

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.