在多维数组上使用 preg_match 返回键值数组
我有一个结构如下的数组:
$data = array(
"abc"=>array(
"label" => "abc",
"value" => "def",
"type" => "ghi",
"desc" => "jkl",
),
"def"=>array(
"label" => "mno",
"value" => "qrs",
"type" => "tuv",
"desc" => "wxyz",
),
);
我想使用 preg_match 和 foreach 循环来对 $data 中包含的数组执行搜索并返回键值对的嵌套数组。
I have an array that is structured as such:
$data = array(
"abc"=>array(
"label" => "abc",
"value" => "def",
"type" => "ghi",
"desc" => "jkl",
),
"def"=>array(
"label" => "mno",
"value" => "qrs",
"type" => "tuv",
"desc" => "wxyz",
),
);
I want to use preg_match with a foreach loop to perform a search on the arrays contained in $data and return the nested arrays of key value pairs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
对于谷歌员工来说,这里有更好的代码
for the googlers out there here's the better code
像这样的东西吗?
Something like this?
如果您使用 PHP 5.5 并在 2015 年查看此问题,这可能是一个更简单的答案:
If you are using PHP 5.5 and are viewing this question in 2015, this might be a more simple answer:
上面的答案都不适合我的情况,所以我将在这里留下我的解决方案,也许它对某人有用
None of the answers above worked on my case, so I'll leave my solution here maybe it can be useful to someone
数组
$haystack
中的列columnName
上不区分大小写的 unicode grepCase-insensitive unicode grep on column
columnName
in array$haystack
preg_match_all 返回与具有特定列名的模式匹配的行。
preg_match_all returns the rows that match a pattern with a specific column name.