Last active
August 27, 2018 07:18
-
-
Save dyazincahya/aa3b13ad9d508b885a51bb5c6bb662e3 to your computer and use it in GitHub Desktop.
PHP Function in_array multidimension
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 | |
function in_array_r($thekey, $arraydata, $strict = false) | |
{ | |
foreach ($arraydata as $item) | |
{ | |
if (($strict ? $item === $thekey : $item == $thekey) || (is_array($item) && in_array_r($thekey, $item, $strict)['found'])) | |
{ | |
return array( | |
"found" => true, | |
"data" => $item | |
); | |
} | |
} | |
return array( | |
"found" => false, | |
"data" => [] | |
); | |
} | |
/**********************/ | |
/*** EXAMPLE USAGE ***/ | |
/********************/ | |
// array data | |
$a = array | |
( | |
array | |
( | |
"no" => "6223423423424", | |
"status" => "ACTIVE", | |
), | |
array | |
( | |
"no" => "6223423421134", | |
"status" => "INACTIVE" | |
) | |
); | |
// call func | |
$b = in_array_r("6223423423424", $b, true); | |
// result | |
echo "<pre>"; | |
var_dump($c); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment