What does the => operator do in the arguments of a foreach loop in PHP? -


this question has answer here:

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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -