简体   繁体   中英

Trying to looping foreach inside for loop statement

I'm trying to foreach inside for loop in laravel controller.

I have tried like this :

$text = "";
$text1 = "";
$sesis = Sesi::all();
for($i=$start_time; $i<$end_time; $i+=86400)
    {
        $text .= "<tr>
        <td>".date('d F Y', $i)."</td".
        foreach ($sesis as $data) {
            $text1 .="<td><button>$data->id</button></td>"
        }."</tr>";
    }
return $text;

but give me an error :

syntax error, unexpected 'foreach' (T_FOREACH)

and i want to know, is it possible to foreach inside foreach statement ?

You have syntax error in the code. So, change your code like this:

$text = "";
$sesis = Sesi::all();
for($i=$start_time; $i<$end_time; $i+=86400)
    {
        $text .= "<tr><td>".date('d F Y', $i)."</td>";
        foreach ($sesis as $data) {
            $text .="<td><button>".$data->id."</button></td>";
        }
        $text = $text."</tr>";
    }
return $text;

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