Home > Backend Development > PHP Tutorial > Find the value of a specified key in an array_PHP Tutorial

Find the value of a specified key in an array_PHP Tutorial

WBOY
Release: 2016-07-13 17:45:54
Original
805 people have browsed it

Find the value of a specified key in an array_PHP Tutorial

HTML







Ajax传值


   

        输入要查找的值:
       
   

    查找的结果为:
   

   
   

 
 
<br>
//Example array search depth<br>
$src_array = array(<br>
'test' => '123',<br>
array(<br>
         'has' => 'OK',<br>
         'find'=> true,<br>
array(<br>
             'depth' => 'soso',<br>
array(<br>
'123' => 'wangbin',<br>
'wangbin' => 'wangbin456',<br>
array(<br>
'wangbin' => 'wangbin123',<br>
),
<p>
),<br>
),<br>
),<br>
);<br>
</p>
Copy after login


php

function find_array_key($find, $src_array)
{
If (is_array($src_array))
{
$src = '';
If (isset($src_array[$find]))
            {
$src .= $src_array[$find];
#Can be improved to delete the found value in search
return $src;
         }else
            {
foreach ($src_array as $key => $value)
                {
If (IS_ARAY ($ Value)) #determine whether an array is an array.                                                 {
                           return find_array_key($find, $value);
                }
            }
              return false;
}
}else{
         return false;
}
}

$src_array = array(

'test' => '123',
array(
         'has' => 'OK',
         'find'=> true,
array(
             'depth' => 'soso',
array(
'123' => 'wangbin',
'wangbin' => 'wangbin456',
array(
'wangbin' => 'wangbin123',
),

),

),
),
);

$username = $_REQUEST['username'];

if($username){
echo find_array_key($username, $src_array);
}else{
echo 'Find failed';
}
?>

Author "wbgod_1987"


http://www.bkjia.com/PHPjc/478622.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478622.htmlTechArticleHTML !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www. w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head meta http-equi...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template