PHP搜索匹配阵列列 [英] PHP Search Array column for match
本文介绍了PHP搜索匹配阵列列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组如下,其中有多个列。我想在一个特定的值的第一列进行搜索,并且具有匹配返回的行。这是可能做到?
I have an array as below, which has multiple columns. I want to search in the first column for a specific value, and have the rows that match returned. Is that possible to do?
例如:
Array (
[0] => Array ( [id] => 1 [column2] => value2 [column3] => value3 [column4] => value4 [column5] => value5 )
[1] => Array ( [id] => 1 [column2] => value2 [column3] => value3 [column4] => value4 [column5] => value5 )
[2] => Array ( [id] => 2 [column2] => value2 [column3] => value3 [column4] => value4 [column5] => value5
)
所以我们可以说我想要搜索的ID列1,有结果显示。如何才能做到这一点?太谢谢你了!
So let's say I want to search the "id" column for "1" and have the results displayed. How can this be done? Thank you so much!
推荐答案
既然你有一个嵌套的阵列
你需要两个迭代:
Since you have an nested Array
you need two iterations:
$filtered = array();
$rows = Your Array;
foreach($rows as $index => $columns) {
foreach($columns as $key => $value) {
if ($key == 'id' && $value == '1') {
$filtered[] = $columns;
}
}
}
这应该做的工作。
这篇关于PHP搜索匹配阵列列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文