Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

Empty Array causing an error

I have a large query and part of it depends upon a returned Array.  If there is no data returned by the query, the Array is empty, obviously.  But My code so far has an area that is looking for the the second part of the Array Data:
<?php
$a = false;
  $b = false; 
  if($wave[0] <= $wave_max) $a = true; 
   if($wave[1] >= $wave_min) $b = true; 
   			
   	$wavelength = '';
   				
   	if($a && $b) $wavelength = true;

Open in new window

So if the return is empty, I get an error on this line:  if($wave[1] >= $wave_min) $b = true; , the second part of the array.
The error message is:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
And refers to that line
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

Thanks Dave.  I have been spinning my wheels for a while.
You're welcome, glad to help.
You may find this function useful, too.
http://php.net/manual/en/function.empty.php