Basically {{ $last= date('Y')-120 }} in this part you are showing the value but you need to assign the value. So assign like this :
<?php $last= date('Y')-120; ?>
Same thing goes for the for loop too.Just compare the value. Do not put it in blade syntax.
<select id="year" name="year" class="form-control ">
{{ $last= date('Y')-120 }}
{{ $now = date('Y') }}
@for ($i = $now; $i >= $last; $i--)
<option value="{{ $i }}">{{ $i }}</option>
@endfor
</select>
Answer from Minhaj Mimo on Stack OverflowBasically {{ $last= date('Y')-120 }} in this part you are showing the value but you need to assign the value. So assign like this :
<?php $last= date('Y')-120; ?>
Same thing goes for the for loop too.Just compare the value. Do not put it in blade syntax.
<select id="year" name="year" class="form-control ">
{{ $last= date('Y')-120 }}
{{ $now = date('Y') }}
@for ($i = $now; $i >= $last; $i--)
<option value="{{ $i }}">{{ $i }}</option>
@endfor
</select>
using @for ($i = $now; $i <= $last; $i--) didn't work for me so I had to use incrementing count.
<div class="form-group">
<label for="task" class="col-sm-1 control-label">Text</label>
@for ($i = 0; $i < $count; $i++)
<div class="col-sm-12">
<input type="text" name="text[{{ $i }}]" id="text[{{ $i }}]" class="form-control">
</div>
@endfor
</div>
foreach is for looping through arrays and other iterable objects, so it doesn't work with the same parameters as a for loop.
Simply change foreach to for.
for ($i = 0; $i < count($orderProduct->column['Position']); $i++) {
$message .= "<p>" . $orderProduct->column['Position'][$i] . " : " . $orderProduct->column['Color'][$i] . "</p>";
}
Firest you have error in your json data
$orderProduct = {"Position":["first","second","third","fourth"],"Color":["Red",Blue,Pink,Teal]}
Blue,Pink,Teal doenst contain single quote or double quote.
So it should be
$orderProduct = '{"Position":["first","second","third","fourth"],"Color":["Red","Blue","Pink","Teal"]}';
then you can use foreach like below
$orderProduct = '{"Position":["first","second","third","fourth"],"Color":["Red","Blue","Pink","Teal"]}';
$data=json_decode($orderProduct);
foreach ($data as $key=>$value){
echo "<h4>".$key."</h4>";
echo implode("<br>",$value);
}
This will ouput like below
Position
first second third fourth
Color
Red Blue Pink Teal
Also you can avoid implode if you want
foreach ($data as $key=>$value){
echo "<h4>".$key."</h4>";
foreach ($value as $subkey=>$subvalue){
echo $subvalue."<br>";
}
}