-2

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 ...

devpro
  • 16,184
  • 3
  • 27
  • 38
Mauliardiwinoto
  • 107
  • 2
  • 10

2 Answers2

1

Define it before use as

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

If you don't declare a new array, and the data that creates / updates the array fails for any reason, then any future code that tries to use the array will warning because the array doesn't exist.

For example, foreach() will throw an error if the array was not declared and no values were added to it. However, no errors will occur if the array is simply empty, as would be the case had you declared it.

Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
1

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 ;
}
...
Ben Bozorg
  • 184
  • 8