[Solved] Array PHP. How to get deep of element in array


You can use the following recursive function to get the depth where the uuid value is found. This version returns value 0 if the uuid value is not found at all.

function searchDepth($uid, $array, $depth = 0)
{
    $depth++;

    foreach ($array as $element)
    {
        if (isset($element['uid']) && $element['uid'] == $uid)
        {
            return $depth;
        }
        else if (isset($element['introducer_users']))
        {
            $result = searchDepth($uid, $element['introducer_users'], $depth);

            if ($result != 0)
            {
                return $result;
            }
        }
    }

    return 0;
}

And to invoke the function with the search uuid and the array

$depth = searchDepth(10, $mang);

0

solved Array PHP. How to get deep of element in array