How To Check If Array Is Empty Or False Value
how to check if array is empty or false value
how, to, check, if, array, is, empty, or, false, value
How To Check If Array Is Empty Or False Value
Post Description: how to check if array is empty or false value
POST# 470
Posted On: Fri Feb 29, 2008 12:01 pm
php help
Topic: 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?





Mon Feb 25, 2008 6:56 am
1
hostman
Reply #1061
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";
}
?>

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload
     
  1. Warning: Mysql_fetch_array(): Supplied Argument Is Not A Valid MySQL Result
  2. Simple Array Example Learn PHP Programming Creating Arrays Learn Tutorial
  3. How To Create Make PHP Forms Using Form Arrays Tutorial
  4. How To Count And Break A Word Into An Array In Php Tutorial Guide
  5. How To Display Array Contents
  6. PHP Using For Loop To Display The Contents Of An Array
  7. How To Count Array Values Php Counting Arrays Holds Variables Script
  8. How To Use For Loop In Php Using Array Tutorial Sample Script
  9. Count And Display Words In A String Into Array Php Sentence Word
  10. How To Make Array Variable Global In PHP Function
  11. How To Count Elements In An Array Find How Many Values Arrays
  12. How To Check If Array Is Empty Or False Value
  13. How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial
  14. How To Display Array Elements With FOR Loop
  15. Php Form Using Array For Field Name Template User Information
  16. Getting Array Elements Values With While Loop Show Display
  17. Display Array Elements Values With Loop
  18. How To Index Arrays And Show All The Elements And Values Of Array
  19. Php Show Values Array
  20. Php Html Display Array
  21. Making An Array From A Mysql Query