Multiple index variables in PHP foreach loop

前端 未结 8 667
名媛妹妹
名媛妹妹 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:13

    If both the arrays are of the same size you can use a for loop as:

    for($i=0, $count = count($courses);$i<$count;$i++) {
     $course  = $courses[$i];
     $section = $sections[$i];
    }
    

提交回复
热议问题