clay1 Posted June 15, 2010 Share Posted June 15, 2010 I am trying to sort records into 2 different 2 dimensional arrays such that I end up with something like: $array1 = array("Boston" = > array(variousrecords), "New York" = > (various records)); So far I have: $array1 = array(); $array2 = array(); while ($recordData = pg_fetch_assoc($recordresults)) { if (in_array($recordData['event city'], $marketsarray1)){ $eventcity = $recordData['event city']; $$eventcity = array($recordData);} elseif (in_array($recordData['event city'], $marketsarray2) ){ $$eventcity = array($recordData);} else { $unsorted[] = $recordData;} } How can I make $array1[$$eventcity] = array($recordData);} ? Quote Link to comment https://forums.phpfreaks.com/topic/204901-2-dimensional-variable-variable-array/ Share on other sites More sharing options...
clay1 Posted June 16, 2010 Author Share Posted June 16, 2010 This seems to be working: $$eventcity = $recordData['event city']; $array1[] = array(${$eventcity} => $recordData);} Quote Link to comment https://forums.phpfreaks.com/topic/204901-2-dimensional-variable-variable-array/#findComment-1072712 Share on other sites More sharing options...
clay1 Posted June 16, 2010 Author Share Posted June 16, 2010 I take that back. while($ix <16){ var_dump($array2[$ix]); $ix++; } var_dump($array2["Walnut Creek"]); First var_dump prints out an array but the keys seem to be duplicating i.e. array2("Walnut Creek" => 1 record, "Boston" => 1 record, "Walnut Creek" => another record) Rather than array2("Walnut Creek" => 5 records, "Boston" => 3 records) When I do the second var_dump I get NULL Quote Link to comment https://forums.phpfreaks.com/topic/204901-2-dimensional-variable-variable-array/#findComment-1072728 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.