我有一个多维数组,我想过滤它,以便只显示特定键的键/值对。
在本例中,这将是“installer”键。如果可能的话,请告诉我
array:3 [
1 => array:8 [
"installer" => "322"
"monday" => "y"
"tuesday" => "y"
"wednesday" => "y"
"thursday" => "n"
"friday" => "y"
"saturday" => "n"
"sunday" => "y"
]
2 => array:8 [
"installer" => "318"
"monday" => "y"
"tuesday" => "y"
"wednesday" => "n"
"thursday" => "y"
"friday" => "n"
"saturday" => "y"
"sunday" => "y"
]
3 => array:8 [
"installer" => "350"
"monday" => "y"
"tuesday" => "n"
"wednesday" => "y"
"thursday" => "y"
"friday" => "y"
"saturday" => "y"
"sunday" => "n"
]
]
如果您想用PHP的方式进行,可以使用array\u column
获取每个数组中installer
键的所有值。
print_r(array_column($data,'installer'));
演示:https://3v4l.org/77aKm
如果您想使用Laravel方式(推荐),您可以使用集合的pluck
方法过滤掉安装程序
键值。
$collection = collect([
[
"installer" => "322",
"monday" => "y",
"tuesday" => "y",
"wednesday" => "y",
"thursday" => "n",
"friday" => "y",
"saturday" => "n",
"sunday" => "y",
],
[
"installer" => "318",
"monday" => "y",
"tuesday" => "y",
"wednesday" => "n",
"thursday" => "y",
"friday" => "n",
"saturday" => "y",
"sunday" => "y",
],
[
"installer" => "350",
"monday" => "y",
"tuesday" => "n",
"wednesday" => "y",
"thursday" => "y",
"friday" => "y",
"saturday" => "y",
"sunday" => "n"
]
]
);
dd($collection->pluck('installer')->all());
本文向大家介绍PHP 二维数组和三维数组的过滤,包括了PHP 二维数组和三维数组的过滤的使用技巧和注意事项,需要的朋友参考一下 废话不多说了,直接给大家贴代码了,具体代码如下所示: 下面一段代码给大家介绍php三维数组变二维数组 关于PHP 二维数组和三维数组的过滤小编就给大家介绍这么多,希望对大家有所帮助!
如何通过子数组值筛选数组?在这个例子中,我有下面的API请求数组,并且希望只构建一个id为2的新数组,该数组具有name=Other name,因为我的过滤器被设置为Other name 是否有方法执行并填充新数组?
我有两个多维数组,我想通过使用其中一个数组的值和另一个数组的键来组合它们。数组如下: 阵列1: 阵列 2: 我想生成的结果数组如下: 有没有一个PHP函数可以用来完成这个任务?
我有一个问题,显示检查的数据在数组在Angular应用程序。当我点击复选框时,我得到一个真值,但数据没有显示。数据具有空值。 stackblitz:https://stackblitz.com/edit/Angular-ivy-kt2uag?file=src%2fapp%2fapp.component.ts 代码: Component.ts 我使用这个函数:
我有这个数组,当我搜索uid时,我需要返回找到密钥的数组,所以如果我搜索“4048”,我应该得到第二个数组。 有什么帮助吗? 提前谢谢
问题内容: 我有一个多维数组,我试图找出如何简单地“回显”数组中的元素。数组的深度未知,因此可以深度嵌套。 对于下面的数组,正确的回显顺序为: 这是我正在谈论的数组: 问题答案: 看来您只是在尝试从每个数组中写入一个重要值。尝试像这样的递归函数: 您还可以使其更具动态性,并将和字符串作为参数传递到函数中(并继续在递归调用中传递它们)。