Skip to content

Instantly share code, notes, and snippets.

@dyazincahya
Last active August 27, 2018 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyazincahya/aa3b13ad9d508b885a51bb5c6bb662e3 to your computer and use it in GitHub Desktop.
Save dyazincahya/aa3b13ad9d508b885a51bb5c6bb662e3 to your computer and use it in GitHub Desktop.
PHP Function in_array multidimension
<?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