What does the greater than '>' symbol do in a PHP array?

  • Thread starter Thread starter Nathan W
  • Start date Start date
N

Nathan W

Guest
such as in this example:

$week=array('mon'=>0, 'tue'=>2);

I'm learning PHP and just like to know what it does. Is it just a way of pointing to the index?
 
It's an associative array.. this '=>' is meant represent an arrow. The text to the left of it is the key and the text to the right of it is the value.

You can access a single value in the array like this:
echo $week['mon'];

You can also loop through the entire array:

foreach ($week as $key => $value) {
echo $key.'=>'.$value.'<br>';
}
 
Back
Top