[PHP-NOTES] note 130663 added to function.in-array

[email protected] ("[email protected]") Wed, 18 Feb 2026 15:54:13 +0000
Newsgroups php.notes
Message-ID <[email protected]>
It's worth the notice that in_array is case-sensitive.
Apart from the very first option of make all lowercase or uppercase, and then compare, I found this elegant solution:

<?php

function in_arrayi(float|int|string $needle, array $haystack):bool {
	return (bool)array_uintersect([$needle],$haystack,strcasecmp(...));
}

$needle = "abc";
$haystack = ["Abc","deF","gHi"];
$result = in_arrayi($needle,$haystack);

var_dump($result);

?>
----
Server IP: 206.189.2.9
Probable Submitter: 2800:a4:c0de:2c00:bc6f:73bf:ab79:1ace
----
Manual Page -- https://php.net/manual/en/function.in-array.php
Edit        -- https://main.php.net/note/edit/130663
Del: integrated  -- https://main.php.net/note/delete/130663/integrated
Del: useless     -- https://main.php.net/note/delete/130663/useless
Del: bad code    -- https://main.php.net/note/delete/130663/bad+code
Del: spam        -- https://main.php.net/note/delete/130663/spam
Del: non-english -- https://main.php.net/note/delete/130663/non-english
Del: in docs     -- https://main.php.net/note/delete/130663/in+docs
Del: other reasons-- https://main.php.net/note/delete/130663
Reject      -- https://main.php.net/note/reject/130663
Search      -- https://main.php.net/manage/user-notes.php