Ardee NetGeek Ardee NetGeek - 3 months ago 21
PHP Question

php foreach error first line

I always have error for first array in table.

foreach ($status_lines as $status_line) {
$xxx [] = $status_line -> status ;
}

if (count(array_unique($xxx)) == 1 && end($xxx) == 'REJECTED') { ?>
<b class="text-gray"> N / A </b>
<?php }

elseif (count(array_unique($xxx)) == 1 && end($xxx) == 'NOT APPROVED') { ?>
<b class="text-gray"> N / A </b>
<?php }



it resulting : Message: Undefined variable: xxx


but for the second line to the end in table is OK ...

Answer

Your variable $xxx has been defined within your foreach block. It is not defined anywhere else.

Define it outside the block as a global variable:

$xxx = array();

Then continue your foreach loop as follows:

foreach ($status_lines as $status_line) {
    $xxx[] = $status_line -> status ;
}
...