mercredi 3 août 2016

in_array fails when using implode in if statement

Why is the following code failing ?

<?php
$terms=array("HELLO","HI","HOWDY");
$row=array("HELLO","HI","Hey");
$chkcond="in_array('".implode("',$"."row".")"." && in_array"."('",$terms)."',$"."row)";

echo $chkcond."<br><br>";

if($chkcond){echo "All Found in Array !<br>";}else{echo "Not Found !<br>";}
?>

The echo result is

in_array('HELLO',$row) && in_array('HI',$row) && in_array('HOWDY',$row)

And the if condition outputs

"All Found in Array !"

When the if condition says that all three 'terms' have to be in the 'row' array to be "All Found in Array", then why is it returning True when "Howdy" doesn't exist in the 'row' array ?

Aucun commentaire:

Enregistrer un commentaire