dongqu7778 2013-12-07 23:25
浏览 23
已采纳

了解foreach循环中的变量赋值[关闭]

I have a pretty basic question:

What is this statement actually doing (specifically the =>$p)?

foreach ($email->parts as $partno=>$p) {

I understand the the basics but the =>$p is not clear

  • 写回答

3条回答 默认 最新

  • duanniesui6391 2013-12-07 23:27
    关注

    In a foreach loop you can ask for both the key and value to be returned

    $array = array('cat' => 'Tom', 'mouse' => 'Jerry');
    foreach($array as $animal => $name) {
        echo $name . ' is a ' . $animal . '<br>';
    }
    

    So the loop will output

    Tom is a cat
    Jerry is a mouse

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?