Search code examples
phpreturn

echo specific array elements


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!


Solution

  • foreach($array as $row){
        if($row < 3){continue;}
        echo $row . '-';
    }
    

    I think you confused return with continue

    The above code will do for you.