How To Check If Array Is Empty Or False Value
Post Description:
Post Tags: how, to, check, if, array, is, empty, or, false, value, free php support, php scripts, php questions, php answers, programming, codes, scripts
This Post Has Been Viewed 1948 Times Since Mon Feb 25, 2008 6:52 am Posted By
php help with 2 replies
Next Post »»
how to make capital letters in php capitalise words
i want to know if you can help me. i have this code
<?php
$myarray= array();
$myarray[0] = "";
$myarray[1] = false;
if($myarray){
echo "this is true";
}else{
echo "this is false";
}
?>
but when i run it, it still comes out true?
when i do this:
PHPCODE:
print_r(array_values($myarray));
it shows me this:
Array ( [0] => )
how can i check or verify that an array has a value of zero or false then?
Comments and replies About How To Check If Array Is Empty Or False Value
you can do two things:
OPTION 1: USE ISSET() FUNCTION
<?php
$myarray= array();
$myarray[0] = "";
$myarray[1] = false;
if(isset($myarray)){
echo "this is true";
}else{
echo "this is false";
}
?>
OPTION 2: USE EMPTY() FUNCTION
<?php
$myarray= array();
$myarray[0] = "";
$myarray[1] = false;
if(empty($myarray)){
echo "this is true";
}else{
echo "this is false";
}
?>