简体   繁体   中英

how to create multiple array in one foreach

Is it possible to have one foreach loop in PHP with multiple array?

im create this code but not working

<?php foreach ($data as $value) && ($data1 as $value1) { ?>

You can try

foreach (array_combine($data, $data1) as $value => $value1)

Insted of

<?php foreach ($data as $value) && ($data1 as $value1) { ?>

OR Another Solution is

foreach($courses as $course)
{
    foreach($sections as $section)
    {
    }
}

$data is array, having more or even elements than $data1

 $i = 0;
 $keys = array_keys($data1);

 foreach($data as $value){
   $value1 = $data1[$keys[$i]];
   $i++;
 }

Just like @Confused suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM