faqts : Computers : Programming : Languages : PHP : Common Problems : Arrays

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 8 people (25%) answered Yes
Recently 2 of 8 people (25%) answered Yes

Entry

How can I compare the values in an array and then unset the array if they are all NULL or the same?

Feb 14th, 2002 09:52
Ben Udall, J Fried,


This should work.  It will also unset arrays with 0 or 1 values.
for ($i=1; $i<count($array); ++$i)
{
   if ($array[$i] != $array[$i-1])
      break;
}
if (count($array) == 0 || $i == count($array))
   unset($array);