Skip to main content
added 133 characters in body
Source Link
rynhe
  • 2.5k
  • 1
  • 22
  • 27

if your array like this

<?php
$array = array(
    function in_multiarray         array($elem"name" => "Robert", $array"Age" => "22", "Place" => "TN"), 
    {          array("name" => "Henry", "Age" => "21", "Place" => "TVL")
         );

Use this

function in_multiarray($elem, $array,$field)
{
    $top = sizeof($array) - 1;
        $bottom = 0;
        while($bottom <= $top)
        {
            if($array[$bottom]$array[$bottom][$field] == $elem)
                return true;
            else 
                if(is_array($array[$bottom]$array[$bottom][$field]))
                    if(in_multiarray($elem, ($array[$bottom]$array[$bottom][$field])))
                        return true;
                    
            $bottom++;
        }        
        return false;
    }
?>

example : echo in_multiarray("22", $array,"Age");

<?php

    function in_multiarray($elem, $array)
    {
        $top = sizeof($array) - 1;
        $bottom = 0;
        while($bottom <= $top)
        {
            if($array[$bottom] == $elem)
                return true;
            else 
                if(is_array($array[$bottom]))
                    if(in_multiarray($elem, ($array[$bottom])))
                        return true;
                    
            $bottom++;
        }        
        return false;
    }
?>

if your array like this

$array = array(
              array("name" => "Robert", "Age" => "22", "Place" => "TN"), 
              array("name" => "Henry", "Age" => "21", "Place" => "TVL")
         );

Use this

function in_multiarray($elem, $array,$field)
{
    $top = sizeof($array) - 1;
    $bottom = 0;
    while($bottom <= $top)
    {
        if($array[$bottom][$field] == $elem)
            return true;
        else 
            if(is_array($array[$bottom][$field]))
                if(in_multiarray($elem, ($array[$bottom][$field])))
                    return true;
                
        $bottom++;
    }        
    return false;
}

example : echo in_multiarray("22", $array,"Age");

Source Link
rynhe
  • 2.5k
  • 1
  • 22
  • 27

<?php

    function in_multiarray($elem, $array)
    {
        $top = sizeof($array) - 1;
        $bottom = 0;
        while($bottom <= $top)
        {
            if($array[$bottom] == $elem)
                return true;
            else 
                if(is_array($array[$bottom]))
                    if(in_multiarray($elem, ($array[$bottom])))
                        return true;
                    
            $bottom++;
        }        
        return false;
    }
?>