Created
March 14, 2019 05:25
-
-
Save awolad/b8ca04787d8ec44a1fc52efb700b9856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// check only array value | |
function in_array_r($needle, $haystack, $strict = false) | |
{ | |
foreach ($haystack as $item) { | |
if (($strict ? $item === $needle : $item == $needle) || | |
(is_array($item) && in_array_r($needle, $item, $strict))) { | |
return true; | |
} | |
} | |
return false; | |
} | |
// check by array index | |
function in_array_r_k($needle, $haystack, $keyToCheck, $strict = false) | |
{ | |
foreach ($haystack as $item) { | |
if (($strict ? $item[$keyToCheck] === $needle : $item[$keyToCheck] == $needle) || | |
(is_array($item) && in_array_r_k($needle, $item, $keyToCheck, $strict))) { | |
return true; | |
} | |
} | |
return false; | |
} | |
$roleMenuPermission = [ | |
['role_menu_permission_id' => 1, 'role_id' => 9, 'menu_id' => 1], | |
['role_menu_permission_id' => 2, 'role_id' => 2, 'menu_id' => 2], | |
['role_menu_permission_id' => 3, 'role_id' => 3, 'menu_id' => 4], | |
]; | |
//echo in_array_r(9, $roleMenuPermission); | |
echo in_array_r_k(9, $roleMenuPermission, 'menu_id'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment