Thanks to those who chimed in...But I modified my original program and now am even more perplexed:
Here's the new code:
if ($_SESSION["cart_array"][$key]["Kit"]==true) {echo "<br>1 True<br>";}
if ($_SESSION["cart_array"][$key]["Kit"]=="true") {echo "<br>1b True<br>";}
if ($_SESSION["cart_array"][$key]["Kit"]==false){echo "2 True<br>";}
if ($_SESSION["cart_array"][$key]["Kit"]=="False"){echo "3 True<br>";}
if ($_SESSION["cart_array"][$key]["Kit"]==True){echo "4 True<br>";}
if ($_SESSION["cart_array"][$key]["Kit"]==False){echo "5 True<br>";}
;}
?>
For simplicity I created an array with just one line. The Var_dump follows: array(1) { [0]=> array(11) { ["groupId"]=> string(5) "25778" ["GroupName"]=> string(9) "'1canoe2'" ["StylePatternColor"]=> string(30) "A-7557-C " ["Price"]=> string(4) "5.25" ["StandardPutUp"]=> string(2) "15" ["Discount"]=> string(3) ".25" ["ListPrice"]=> string(3) "5.5" ["Quantity"]=> string(1) "1" ["PromiseDate"]=> string(10) "07/01/2014" ["DoNotShipBefore"]=> string(10) "07/01/2014" ["Kit"]=> string(5) "False" } }
See that Kit is "False". Yet the results when I run the program are as follows: 1 True 3 True 4 True
How can this be? 1 is supposed to match if the value is true (boolean), three is supposed to match if the value is false (boolean) and four is supposed to match if True (boolean, I wanted to test for case sensitivity). Anyway, "False" matched but False (boolean) did not. And, note, these were all with ==, not ===. How come? Thanks again for your input. I'm tearing my hair out.
I am having trouble understanding how to evaluate array variables in php.
<?php
session_start();
print_r($_SESSION["cart_array"]);
$NumberOfLineItems = count($_SESSION["cart_array"]);
for ($key=0; $key<$NumberOfLineItems; $key++) {
if ($_SESSION["cart_array"][$key]["Kit"]==true) {echo "<br>1 <br>";}
if ($_SESSION["cart_array"][$key]["Kit"]==false){echo "2 <br>";}
if ($_SESSION["cart_array"][$key]["Kit"]===true){echo "3 <br>";}
if ($_SESSION["cart_array"][$key]["Kit"]===false){echo "4 <br>";}
;}
?>
session_start(); Print_r($_SESSION["cart_array"]);
I get: Array ( [0] => Array ( [groupId] => 255... [Kit] => True ) )
1
In short, the double equals does find the match, but the triple does not? I would have thought it would have been exactly the opposite. From what I've read here it seems like the more specific should have the least ambiguity.
Why does the exact equality fail but the double= find a match?
I've read about the differences, but I am obviously missing something basic. Thanks in advance.
The last bit, Kit, has had me up all night.