Thank you for clearing me that. Now that being the case I have compare the array to empty string like
if ( $_POST['frmSearch']['types'] == '' )
to false
if ( $_POST['frmSearch']['types'] == false )
To Null
if ( $_POST['frmSearch']['types'] == NULL )
to zero
if ( $_POST['frmSearch']['types'] == 0 )
And it works ok, becasue it is empty there fore it will display a message for instance "no results were found.
But when it evalutes to true meaning there is something in it, it will still display “no Results were found” as it was emtpy.
I make a print_r or a var_dump and when assign something to the array, it shows is not empty, there is something in it, which means it evaluates to true at that points. the var dump and print_r looks as fallows when the array has something in it, or evaluates to true meaning is not empty.
var_dump
array(5) {
[“name”]=>
string(0) “”
[“zipcode”]=>
string(0) “”
[“state”]=>
string(0) “”
[“frmSearch”]=>
array(1) {
[“types”]=>
array(1) {
[0]=>
string(1) “5”
}
}
[“submit”]=>
string(6) “Submit”
}
print_r
Array
(
[name] =>
[zipcode] =>
[state] =>
[frmSearch] => Array
(
[types] => Array
(
[0] => 5
)
)
[submit] => Submit
)
The var_dump and print_r clearly shows that the array is not empty and there is something in it. But still it will display the message “no results were found” when the test is as below.
if ( trim($_POST['name']) == '' && $_POST['zipcode'] =='' && $_POST['state'] =='' && $_POST['frmSearch']['types']==false )
{ echo"no results were found"}
else
{valid code...}
I thought that the test that the types array is submitted to should echo no results when it evaluates to false, empty, 0, or NULL, but if it evaluates to true it should go to the valid code. But it still displaying the “no results were found” when it evaluates to true or false.
I still don’t understand, is there something wrong with the test? The test will work as expected when I take the array types test
&& $_POST['frmSearch']['types']==false