Syntax
in_array($value, $allowed, true)Examples
PHP strict array membership
Run as a PHP 8.0+ CLI script, for example php example.php. The multibyte example additionally requires mbstring.
<?php
$allowed = [10, 20, 30];
var_export(in_array('20', $allowed, true)); echo PHP_EOL;
var_export(in_array(20, $allowed, true)); echo PHP_EOL;- Output: false, then true. The string 20 and integer 20 are different under strict comparison.
Best practices
- Normalize and validate input intentionally before checking membership. Use array_key_exists when searching keys instead of values.
Runtime & versions
PHP runtime on a server or CLI. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
PHP Manual