View Single Post
Old 01-04-2013, 04:04 AM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Best way to check if variable is empty

I have a variable called $messagesToUpdate that holds any and all Messages that have been checked so that an action can be taken on them.

This variable is populated using the implode function if values were submitted in one of two $_POST arrays.

An example of what this variable would hold if the User selected some Messages to take actions on, would be this...

Code:
$messagesToUpdate = 52, 51, 49, 39, 38, 10, 8, 6, 5, 2, 1

So on to my question...

If this variable has at least one value, then I want to run an UPDATE query, but if it is blank then the query should not be run.


What is the best way to check if this variable is blank?


I was starting to use this, but am not sure if it covers all cases...
Code:
	if (!empty($messagesToUpdate)){
		// Update Selected Messages.
				
	}else{
		// Do nothing.
				
	}
I'm unsure what is the best way to check for Blank, Null, Empty, Zero-Length String, etc.

Suggestions??

Thanks,


Debbie
doubledee is offline   Reply With Quote