【发布时间】:2020-05-07 11:55:34
【问题描述】:
我遇到了数组转换问题 我去使用 laravel 集合使用 map 或 php 数组
大批 ( [0] => 数组 ( [id] => 3487 [title_fa] => 父亲 [代码] => 01 [father_id] => 0 [webmaster_id] => 8 [孙子] => 数组 ( [id] => 3488 [title_fa] => 孩子 1 [代码] => 02 [父亲ID] => 3487 [孙子] => ) ) [1] => 数组 ( [id] => 3489 [title_fa] => 父亲 2 [代码] => 03 [father_id] => 3488 [孙子] => 数组 ( [id] => 3490 [title_fa] => 孩子 2 [代码] => 04 [father_id] => 3489 [孙子] => ) ) )数组转换成数组
大批 ( [0] => 数组 ( [title_fa] => 父亲 [代码] => 01 ) [1] => 数组 ( [title_fa] => 父亲>孩子1, [代码] => 0102 ) [2] => 数组 ( [title_fa] => 父亲2 [代码] => 03 ) [3] => 数组 ( [title_fa] => 父亲2>孩子2 [代码] => 0304 ) )Illuminate\Support\Collection::filter()
public function filter(callable $callback = null)
{
if ($callback) {
return new static(Arr::where($this->items, $callback));
}
return new static(array_filter($this->items));
}
【问题讨论】:
-
数组将只有一个元素树
[0]?如果不止一个,它会是什么样子? -
检查我的答案。
-
你的问题是什么?有什么代码需要分享吗?
-
是数组多元素树
标签: php arrays laravel collections