Checking if an Element Exists in a PHP Array
To check if an element exists in an array, the
function in_array is used.
See the example:
<?php
$arr = ['ab', 'cd', 'ef'];
$res = in_array('ab', $arr); // check if the array contains the string 'ab'
var_dump($res);
?>
Code execution result:
true