使用输入字段的Php搜索数组 [英] Php search array using input field
本文介绍了使用输入字段的Php搜索数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
引用:
当我在输入框中输入任何字母rana等时,它应显示所有项目全部包含在salald列表中,我该怎么做?任何人都可以帮我解决这个问题,下面是我试过的代码。
when i enter any letter say "ra" "na" etc in the input box it should display all the items which all contain in the salald list, how can i do this ? can any one help me to solve this problem, Below is the code what i have tried with.
我尝试了什么:
What I have tried:
<!DOCTYPE html>
<html>
<body>
<?php
$veggies = array("Potato", "Cucumber", "Carrot", "Orange", "Green Beans", "onion");
$fruits = array("Apple", "Banana", "orange", "Pineapple", "Grapes", "Watermelon");
$salad = array_merge ($veggies, $fruits);
$Object = 'ra';
$search = array_filter($salad, function($list) use ($Object)
{
return ( stripos($list, $Object) !== FALSE );
});
print_r($search);
?>
<form method="POST">
Search item: <input type="text" name="txt" ><br> <br>
<input type="submit">
</form>
</body>
</html>
推荐答案
veggies = array(Potato,Cucumber,胡萝卜,橙,青豆,洋葱);
veggies = array("Potato", "Cucumber", "Carrot", "Orange", "Green Beans", "onion");
fruits = array(Apple,Banana,orange,Pineapple,Grapes ,西瓜);
fruits = array("Apple", "Banana", "orange", "Pineapple", "Grapes", "Watermelon");
salad = array_merge(
salad = array_merge (
这篇关于使用输入字段的Php搜索数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文