Need help checking if an array is empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Need help checking if an array is empty

Post by someguyhere »

Here is what I'm trying:

Code: Select all

if (isset($related_keywords)) {
$related_list = ul($related_keywords);
}
(obviously $related_keywords is the array)

Since it is set, this doesn't work, even though the elements in the array are empty. Can someone point me in the right direction?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Need help checking if an array is empty

Post by Darhazer »

try with

Code: Select all

if (!emtpy($related_keywords))
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Need help checking if an array is empty

Post by someguyhere »

No dice. How about this...what should I change here?

Code: Select all

if (empty($related_keywords))
    $related_list = NULL;
else
$related_list = "<h3>Related keywords</h3>".ul($related_keywords);
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Need help checking if an array is empty

Post by someguyhere »

Solved it:

Code: Select all

if (empty($related_keywords[0]))
    $related_list = NULL;
else
$related_list = "<h3>Related keywords</h3>".ul($related_keywords);
Post Reply