Monday, 15 September 2014

php - Create a multidimensional array from mysql data -



php - Create a multidimensional array from mysql data -

i wondering how multidimensional array looks this:

array( "wifi" => array( 16 => 499, 32 => 599, 64 => 699 ), "wifi+3g" => array( 16 => 629, 32 => 729, 64 => 829) );

out of mysql table looks this:

id, model, grootte, prijs 1, wifi, 16, 449 2, wifi, 32, 549 3, wifi+3g, 16, 499 4, wifi+3g, 32, 599

just utilize 1 or more fields db results keys in array:

$arr = array(); while($row = mysql_fetch_assoc($result)) { $arr[$row['somekey']][$row['otherkey']] = $row; }

php mysql multidimensional-array

No comments:

Post a Comment