How To Check If Array Is Empty Or False Value

Mobile
feeds
Welcome Login | Register

How To Check If Array Is Empty Or False Value
  Forums Index
      » PHP Forums
        » » how to check if array is empty or false value



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
How To Check If Array Is Empty Or False Value
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?




Leave Your Comments






Share
URL:
You can use this HTML code to put it on your website to show your friends this wallpaper. Use this code on your profile like myspace, friendster, Facebook or others. Just Copy and Paste it in your HTML on your websites



Fourms BBCODE:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums





Comments and replies About How To Check If Array Is Empty Or False Value




:: 1 :: Reply #43023 Reply By hostman On Mon Feb 25, 2008 6:56 am
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";
}
?>
:: 2 :: Reply #55741 Reply By dreamluverz On Fri May 30, 2008 1:07 am
you got this result
array ( [0] => )
because you have an empty string for the first element of your array so using the if condition you have it won't surely work.