note 125568 added to function.in-array

From: Date: Fri, 04 Dec 2020 14:53:03 +0000
Subject: note 125568 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-215934@lists.php.net to get a copy of this message
A function to check an array of values within another array. <?php /** * Return TRUE if any value in neddles exists in haystack (values or keys) or FALSE. */ function array_in_array_exists($aNeedles, $aHaystack_values, $aHaystack_keys = null) { $needles = (is_string($aNeedles))? explode(',', $aNeedles) : $aNeedles; if (is_array($aHaystack_values)) { $search_func = 'in_array'; $haystack = $aHaystack_values; } else { $search_func = 'array_key_exists'; $haystack = $aHaystack_Keys; } return !empty(array_filter($needles, function($e) use ($search_func, $haystack) { return call_user_func($search_func, $e, $haystack); } )); } // Usage example: var_dump( array_in_array_exists(array('000', '123'), array('123','456')) ); ?> bool(true) Second element '123' of needles was found as first element of haystack, so it return TRUE. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.156.130 (proxied: 2804:14d:78b1:5eea:b781:455c:d56b:7358) ---- Manual Page -- http://php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/125568 Del: integrated -- https://master.php.net/note/delete/125568/integrated Del: useless -- https://master.php.net/note/delete/125568/useless Del: bad code -- https://master.php.net/note/delete/125568/bad+code Del: spam -- https://master.php.net/note/delete/125568/spam Del: non-english -- https://master.php.net/note/delete/125568/non-english Del: in docs -- https://master.php.net/note/delete/125568/in+docs Del: other reasons-- https://master.php.net/note/delete/125568 Reject -- https://master.php.net/note/reject/125568 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215934) next »