What does the => operator do in the arguments of a foreach loop in PHP? -
this question has answer here:
- what “=>” mean in php? 6 answers
- reference — symbol mean in php? 15 answers
another clear n00b question:
in following snippet of code (that works fine), '=>' operator do? thought creating associative arrays. going on here?
any explanation helpful.
foreach ($parent $task_id => $todo) { echo "<li>$todo"; if (isset($tasks[$task_id])) { make_list($tasks[$task_id]); } echo '</li>'; }
it splits key , value element of array.
example:
$fruitcolor = array('apple'=>'red', 'banana'=>'yellow'); foreach($fruitcolor $fruit => $color){ echo $fruit . ' = ' . $color . "<br>\n"; } outputs:
apple = red<br> banana = yellow<br>
Comments
Post a Comment