在PHP中的数组对象中搜索值

Array
(
    [0] => Array
        (
            [ADADCD] =>       
        )
    [1] => Array
        (
            [ADADCD] => ?     
        )

    [2] => Array
        (
            [ADADCD] => HOSP1 
        )

    [3] => Array
        (
            [ADADCD] => HOSP2 
        )

    [4] => Array
        (
            [ADADCD] => H1    
        )

)

We have an array like this ,I want to search a specific value like HOSP2,What is the process to get the value at index.

<?php
$array = your array;
$key = array_search('HOSP2', $array);
echo $key;
?>

Output: ADADCD

http://php.net/manual/en/function.array-search.php

Just try with array_search

$key = array_search(array('ADADCD' => 'HOSP1'), $inputArray);

Loop trough the array and return the index on which you find the value you are looking for.

$searchIndex = -1;
foreach ( $yourArray as $k => $v ) {
  if ( $v['ADADCD'] == 'search value' ) {
    $searchIndex = $k;
    break;
  }
}

You can use a combination of foreach() and in_array().

So, first looping through all the indices of the array using foreach().

foreach ($array as $key => $subarray)
   if (in_array($string, $subarray))
       return $key;

So, now for an array like this:

Array
(
    [0] => Array
        (
            [ADADCD] =>       
        )
    [1] => Array
        (
            [ADADCD] => ?     
        )

    [2] => Array
        (
            [ADADCD] => HOSP1 
        )

    [3] => Array
        (
            [ADADCD] => HOSP2 
        )

    [4] => Array
        (
            [ADADCD] => H1    
        )
)

Output

2

Fiddle: http://phpfiddle.org/main/code/t6b-g9r