[英]How can I search in array
I have databases with encrypted datas (name and surname). 我有带有加密数据(名称和姓氏)的数据库。 In my code I retrieves data to array and decrypt name and surname. 在我的代码中,我检索要数组的数据并解密名称和姓氏。
for ($i=0;$i<$pocet;$i++)
{
$row= mysqli_fetch_array($vysledek);
$name = $c_hash->decrypt($row['name']);
$surname = $c_hash->decrypt($row['surname']);
$a_name['id']=$name;
//echo $a_name['id'].' ';
$a_surname['id']=$surname;
//echo $a_surname['id'];
//echo '<br />';
}
enter code here
But how can I do searching in this array? 但是,如何在该数组中搜索? For example user want to find name = "John". 例如,用户要查找名称=“ John”。 Please, can smb help me or give me a advice? 请,smb可以帮助我还是给我建议?
Thanks M. 谢谢M.
How about array_search
or in_array
? array_search
或in_array
怎么样?
please provide your full code.its not enough for understand your need.I guess you ask for code like this. 请提供完整的代码。它不足以理解您的需求。我想您要求提供这样的代码。
if (in_array("John", $a_name)) {
echo "John found";
}
if you want to search within an array you can use in_array : 如果要在数组中搜索,可以使用in_array:
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
or if you want to search in associative array 或者如果您想在关联数组中搜索
<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
echo "The 'first' element is in the array";
}
?>
and this one returns the first corresponding key of that value in the array 这个返回数组中那个值的第一个对应的键
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array); // $key = 1;
?>
hope these codes help you out 希望这些代码对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.