Jump to content

[SOLVED] Array with all values NULL, but "empty" does not work


lopes_andre

Recommended Posts

Hi,

 

I'am a novice programmer. And I'am with some dificulties in this code...

 

if (!empty($c_pesquisa)) {
            	if (empty($aCategoria)) {
            		$query_ = $query_ . " c_anuncio like '%{$c_pesquisa}%'";
            	} else {
            	$query_ = $query_ . " AND c_anuncio like '%{$c_pesquisa}%'"; 		
            	}
            }

 

The variable $aCategoria is an array, the values inside the array are all "null" in my debug but the code jumps to "$query_ = $query_ . " AND c_anuncio like '%{$c_pesquisa}%'";" instead of "$query_ = $query_ . " c_anuncio like '%{$c_pesquisa}%'";"

 

What I'am doing wrong?

 

 

Best Regards, André.

Link to comment
Share on other sites

If an array contains any values it will not be empty, whether the values are null, "", or what ever.  (array() is considered empty.)

 

 

You will either have to unset() null key/val pairs, or you will have to make a function that looks for a value in an array that is not null.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.