If statement in Loop

ma marcelwolf 29 Apr, 2020
I have a data array with for example
[bestellijst] => Array
        (
            [0] => Array
                (
                    [aantal] => 0
                    [artikel] => Pan y aioli (Brood met Spaanse knoflookmayonaise)
                    [prijs] => € 2,60
                )

            [1] => Array
                (
                    [aantal] => 1
                    [artikel] => Pan y aioli, tapenade y mantequilla con hierbas (Brood met Spaanse knoflookmayonaise, tapenade en kruidenboter)
                    [prijs] => € 4,65
                )
I can loop through the data but is it possible to get only the results back where 'aantal' is bigger then zero?
​
Something like
if ({var:loop6.row.aantal} >= 1) {
{var:loop6.row.aantal}
{var:loop6.row.artikel}
{var:loop6.row.prijs}
}
Gr GreyHead 30 Apr, 2020
Hi marcelwolf,
​
The easiest way is probably to use a PHP action. You can loop through the array and unset all the entries where the count is 0. After that you can continue to work with the remaining entries.
​
Bob
he healyhatman 30 Apr, 2020
In a php block: Use $this->get in place of {var: and $this->data in place of {data:
​
return array_filter($this->data('data_name'), function($entry) {
return $entry['aantal'] > 0;
}
​
ALTHOUGH where are you getting this data? If you're getting it from a database why not just restrict the query?
This topic is locked and no more replies can be posted.