Re: [PHP] check if any element of an array is not "empty"
- From: quickshiftin@xxxxxxxxx ("Nathan Nobbe")
- Date: Wed, 30 Apr 2008 14:51:30 -0600
On Wed, Apr 30, 2008 at 2:36 PM, afan pasalic <afan@xxxxxxxx> wrote:
hi,
as a result of one calculation I'm receiving an array where elements
could be 0 or date (as string yyyy-mm-dd hh:ii:ss).
I have to check if any of elements of the array is "date" or if all
elements of the array is 0?
If I try array_sum($result) I'll get 0 no matter what (0 + $string = 0).
I know I can do something like:
foreach($result as $value)
{
if ($value !=0)
{
$alert = true;
}
}
or
if (in_array($result, '-'))
{
$alert = true;
}
but I was thinking if there is the function does that.
i don think theres a function for that; and to be performance conscience, if
just one occurrence of a date is all you need to know its not all 0's then
break out of the loop once youve found that.
foreach($result as $value)
{
if ($value !== 0)
{
$alert = true;
break;
}
}
-nathan
- References:
- check if any element of an array is not "empty"
- From: afan pasalic
- check if any element of an array is not "empty"
- Prev by Date: check if any element of an array is not "empty"
- Next by Date: Re: check if any element of an array is not "empty"
- Previous by thread: check if any element of an array is not "empty"
- Next by thread: Re: check if any element of an array is not "empty"
- Index(es):
Relevant Pages
|