Reputation:
foreach($arrhome as $el){
echo $el['id'] . '-';
}
Result:
1-2-3-4-5-6-7-8-9-
Now I want to echo only if id > 3
It can be done this way:
if($el['id'] > 3){
echo $el['id'] . '-';
}
But I want this way:
if($el['id'] < 3){return;}
echo $el['id'] . '-';
Nothing is echoed!
Upvotes: 1
Views: 60
Reputation: 8338
foreach($array as $row){
if($row < 3){continue;}
echo $row . '-';
}
I think you confused return
with continue
The above code will do for you.
Upvotes: 3
Reputation: 54841
return
stops your script/function execution. In your case you should use continue
so as to move to next iteration:
foreach($arrhome as $el){
if($el['id'] < 3) {
continue;
}
echo $el['id'] . '-';
}
Upvotes: 0
Reputation: 6359
foreach($arrhome as $el){
if(!($el['id'] < 3)){
echo $el['id'] . '-';
}
}
Upvotes: 0