0

another clear n00b question:

In the following snippet of code (that works fine), what does the '=>' operator do? I thought it was for creating associative arrays. Is that going on here?

Any explanation helpful.

    foreach ($parent as $task_id => $todo)
       {
            echo "<li>$todo";

            if (isset($tasks[$task_id]))
            {
                make_list($tasks[$task_id]);
            }
            echo '</li>';
        }  
DBWeinstein
  • 8,605
  • 31
  • 73
  • 118

1 Answers1

3

It splits the key and value for that element of the array.

Example:

$fruitColor = array('apple'=>'red', 'banana'=>'yellow');

foreach($fruitColor as $fruit => $color){
  echo $fruit . ' = ' . $color . "<br>\n";
}

Outputs:

apple = red<br>
banana = yellow<br>
Matt
  • 5,315
  • 1
  • 30
  • 57