samedi 30 janvier 2021

arrays and if statements and accessing each index position

I am not sure I understand if statements and how they access arrays as well as I would like. I have this array:

If I var_dump($count) I get:

array(1) { [0]=> object(stdClass)#2472 (1) { ["nmbr_tables"]=> string(1) "4" } } array(1) { [0]=> object(stdClass)#2445 (1) { ["nmbr_tables"]=> string(1) "0" } } array(1) { [0]=> object(stdClass)#2452 (1) { ["nmbr_tables"]=> string(1) "0" } }

So I write

if($count >= 1){echo "hello";} else {echo "no";}; 

my expected output would be:

hello
no
no

Since the first index position has the nmbr "4" and then the next two have the nmbr "0"

Instead what I am getting is:

hellohellohello

Seeming to indicate that it is only paying attention to the first index position.

So then I thought maybe:

   foreach($count  as $val){
   if($count >= 2){echo "hello";} else {echo "no";};
   };

No difference.

Aucun commentaire:

Enregistrer un commentaire