Multiple index variables in PHP foreach loop

前端 未结 8 508
名媛妹妹
名媛妹妹 2020-11-30 04:52

Is it possible to have a foreach loop in PHP with multiple \"index\" variables, akin to the following (which doesn\'t use correct syntax)?

forea         


        
相关标签:
8条回答
  • 2020-11-30 05:24

    No, because those arrays may have other number of items.

    You must explicitely write something like that:

    for ($i = 0; $i < count($courses) && $i < count($sections); ++$i) {
        $course = $courses[$i];
        $section = $sections[$i];
    
        //here the code you wanted before
    }
    
    0 讨论(0)
  • 2020-11-30 05:28

    like this?

    foreach($array as $b=>$c){
    
    }
    
    0 讨论(0)
提交回复
热议问题