我正在寻找给定此数组的函数:
array(
[0] =>
array(
['text'] =>'I like Apples'
['id'] =>'102923'
)
[1] =>
array(
['text'] =>'I like Apples and Bread'
['id'] =>'283923'
)
[2] =>
array(
['text'] =>'I like Apples, Bread, and Cheese'
['id'] =>'3384823'
)
[3] =>
array(
['text'] =>'I like Green Eggs and Ham'
['id'] =>'4473873'
)
etc..
我要找针
“面包”
并得到以下结果
[1] =>
array(
['text'] =>'I like Apples and Bread'
['id'] =>'283923'
)
[2] =>
array(
['text'] =>'I like Apples, Bread, and Cheese'
['id'] =>'3384823'
原文由 Chamilyan 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用
array_filter
。您可以提供一个回调来决定哪些元素保留在数组中,哪些元素应该被删除。 (回调的返回值false
表示应该删除给定的元素。)像这样:想要查询更多的信息:
array_filter
strpos
返回值