hazmat152 Posted June 16, 2012 Share Posted June 16, 2012 $result = mysql_query($query) or die('cannot get results!'); while($row = mysql_fetch_assoc($result)) { $events[$row['event_date']][] = $row; } Hi. I'm brand new to PHP and I don't quite understand what the line $events[$row['event_date']][] = $row; does. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/264282-extreme-noob-question/ Share on other sites More sharing options...
xyph Posted June 16, 2012 Share Posted June 16, 2012 The bracket notation refers to arrays http://php.net/manual/en/language.types.array.php Here's some example code <?php $array['test'][0] = 'foobar'; $key = 'test'; echo $array[$key][0]; // Outputs foobar // Adds a new entry on to the end of the array $array[$key][] = 'kasbah'; print_r($array); /* Outputs Array ( [test] => Array ( [0] => foobar [1] => kasbah ) ) */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/264282-extreme-noob-question/#findComment-1354351 Share on other sites More sharing options...
Barand Posted June 16, 2012 Share Posted June 16, 2012 ... I don't quite understand what the line $events[$row['event_date']][] = $row; does. Specifically, it creates an events array where the key is the event date and the value is another array containing the event data eg Array ( [2012-06-16] => Array ( [event_id] => 1 [event_date] => 2012-06-16 [event] => Rock Festival [venue] => Chester ) [2012-06-23] => Array ( [event_id] => 2 [event_date] => 2012-06-23 [event] => Beerfest [venue] => Stoke-on-Trent ) ) Quote Link to comment https://forums.phpfreaks.com/topic/264282-extreme-noob-question/#findComment-1354353 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.