如何在搜索后返回数组的索引值。
$sql=mysql_query("SELECT id,userName,email FROM user ORDER BY id ASC");
$myArray=array();
while($row=mysql_fetch_array($sql)){
$myArray[$row['eMail']]=$row;
}
我收到电子邮件作为GET变量,我需要像那样搜索
$search = $_GET["eMail"];
if (isset($myArray[$search])) {
echo $my_values[$search];
$isEmailStored= 1; // **means that I have but in WHICH INDEX I need to find out that**
}
else {
$isEmailStored=0;
}
答案 0 :(得分:0)
此array_search可以帮助您
//example
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array); // $key = 1;
//你的代码
if ( array_search($search,$my_values ) {
echo $my_values[$search];
$isEmailStored= 1; // means that I have but in WHICH INDEX I need to find out that
}