Lucas Kauffman
Lucas Kauffman

Reputation: 6881

array php looping value and key

I'm trying to check value's of keys :

$errorArray=array();
 $naamarray["naam"]=false;
 $naamarray["voornaam"]=false;
 $naamarray["adres"]=false;
 $naamarray["woonplaats"]=false;
 $naamarray["postcode"]=false;
 $naamarray["telefoonnummer"]=false;
 $naamarray["geboortedatum"]=false;
 $naamarray["adres"]=false;
 $naamarray["wachtwoord"]=false;
 $naamarray["email"]=false;
 $naamarray["email"]=true;

  foreach($naamarray as $key => $value){
        if($value == false){
            array_push($errorArray,$key);
            echo $key;
            echo $value;
        }
 }

But the value never get's shown, what is my mistake ?

Upvotes: 2

Views: 108

Answers (6)

Sarfraz
Sarfraz

Reputation: 382686

The false is boolean type in php. Since you have assigned that to your array values, you need to use var_dump to see actual value for your keys :

var_dump($key);

See the var_dump manual for more info


You may want to assign string values to your array values instead.

Upvotes: 4

user827080
user827080

Reputation:

Funny, the keys do echo on my home server. But then again; echo'ing bool false will not output anything.

Upvotes: 0

madflow
madflow

Reputation: 8490

You cannot echo a boolean variable in PHP. If you just want to debug - use

var_dump($value); 

instead.

Upvotes: 0

genesis
genesis

Reputation: 50976

because they are always false, it means NOTHING

echo false;

gives you

Upvotes: 1

SeanCannon
SeanCannon

Reputation: 77966

Try this:

$errorArray=array();
 $naamarray["naam"]='false';
 $naamarray["voornaam"]='false';
 $naamarray["adres"]='false';
 $naamarray["woonplaats"]='false';
 $naamarray["postcode"]='false';
 $naamarray["telefoonnummer"]='false';
 $naamarray["geboortedatum"]='false';
 $naamarray["adres"]='false';
 $naamarray["wachtwoord"]='false';
 $naamarray["email"]='false';
 $naamarray["email"]='true';

  foreach($naamarray as $key => $value){
        if($value == 'false'){
            array_push($errorArray,$key);
            echo $key;
            echo $value;
        }
 }

Upvotes: 0

Howard
Howard

Reputation: 39197

Please note: echo false does not echo anything.

Upvotes: 1

Related Questions