Jump to content

Extreme Noob Question.


hazmat152

Recommended Posts

  $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.

Link to comment
Share on other sites

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
        )

)
*/
?>

Link to comment
Share on other sites

... 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
        )

)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.