21 of 110 menu

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
English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline