I used to use in_array() function to find if a string exist in an array. But then I find out that there’s a faster method to do this using isset().
First method, using in_array() function:
< ?php
$nama = array("yuna","sakura","miyabi","sena");
if(in_array("yuna",$name)) echo "we have yuna here!";
?>
and seem it’s too slow. PHP will loop the array and check one by one to see if we have yuna in the array.
Then using isset() function as follow:
< ?php
$nama = array("yuna","sakura","miyabi","sena");
if(isset($name['yuna'])) echo "we have yuna here!";
?>
it will just check if yuna is exist, no loop, no pain.
Leave a Reply