Craig Hoffman wrote:
Hi There,
I am trying to write an if statement to see if an array has any values
in it and if it does do something.
for example:
$ticklist2 = array("'$values")
if (array_values(empty($ticklist2))) {
empty() is used to check whether a var isset
and is not null, "" or false - and it returns a boolean
value not an array;
php -r '
$a = null;
$b = false;
$c = "";
var_dump($a,$b,$c);
if (empty($a)) { echo "\$a is empty.\n"; }
if (empty($b)) { echo "\$b is empty.\n"; }
if (empty($c)) { echo "\$c is empty.\n"; }
'
array_values() expected an array as its argument.
maybe it can auto-cast any var it receives to an array
but I don't know (I never use it like that anyway.)
what is does do return an array with an associative keys
'replaced' with numeric keys - come to think of it I don't
use this function at all. any have a good use for the
function, just out of interest?
if you want to remove empty values:
php -r '
$a = array("yeah", null, "", "yeah", "baby!");
var_dump($a,array_filter($a));
'
if you want to remove empty values and duplicates:
php -r '
$a = array("yeah", null, "", "yeah", "baby!");
var_dump($a,array_unique(array_filter($a)));
'
do something
} else {
do something else
}
php -r '
$a = array( null, null );
var_dump($a);
if ($a) { echo "\$a has items.\n"; }
if ($aCnt = count($a)) { echo "\$a has {$aCnt} items.\n"; }
$b = array();
if ($b) { echo "\$b has items.\n"; }
if (empty($b)) { echo "\$b is empty.\n"; }
$c = array("f" => "me");
if (!$c) { echo "\$c is empty items.\n"; }
if (!empty($c)) { echo "\$b is empty.\n"; }
'
I just can't get this to work. Any help would be great.
http://nl2.php.net/echo
http://nl2.php.net/empty
http://nl2.php.net/var_dump
http://nl2.php.net/array
http://nl2.php.net/array_unique
http://nl2.php.net/array_filter
Thanks, Craig H.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php