PHP在数组内搜索

时间:2013-11-18 20:21:34

标签: php arrays search

数组

( 
[1] => Array 
( 
[A] => Rina
[B] => Reding 
[C] => 9987536263 
[D] => 47 
[E] => NO 
) 

[2] => Array 
( 
[A] => Anna 
[B] => Jones 
[C] => 0243055454 
[D] => 90 
[E] => YES 
) 

[3] => Array 
( 
[A] => Mario 
[B] => Arinken 
[C] => 5654678679 
[D] => 80 
[E] => YES
) 

) 

当get是[C]时,如何使用GET函数在此Array输出中搜索? 结果应如下所示:您的结果:[D]考试通过:[E] 即GET 5654678679 和结果 是: 您的结果:80考试通过:是 示例http://goo.gl/rkJwfU 该数组使用“Excel to PHP array”

生成

2 个答案:

答案 0 :(得分:1)

认为您正在寻找array_searchin_array

之类的内容

答案 1 :(得分:0)

$array=Array( 
1 => Array 
( 
'A' => 'Rina',
'B' => 'Reding',
'C' => 9987536263,
'D' => 47,
'E' => 'NO' 
),

2 => Array 
( 
'A' => 'Anna',
'B' => 'Jones',
'C' => '0243055454',
'D' => 90,
'E' => 'YES' 
),

3 => Array 
( 
'A' => 'Mario',
'B' => 'Arinken',
'C' => '5654678679',
'D' => 80,
'E' => 'YES'
) 

);

//$pc=$_GET["PERSONAL_CODE"];
$pc='5654678679';//Test Case
$C=array();
foreach($array as $k=>$v){
  $C[$v['C']]=$k;
}

echo "Your result: ".$array[$C[$pc]]['D']." Exam passed:".$array[$C[$pc]]['E'];