我有这个数组结构。如果我发现[empevalpptwo]空或空,我试图删除那些整个数组,所以如果它[empevalpptwo]是空的,整个数组[4] => Array应该被删除。现在我只是想获取父索引,所以我可以按索引删除它有没有像递归过滤这样的好的解决方案?$kra = array_column($ppform_plan->toArray(), 'kra');$emp_eval_pptwo = array_search('', array_column($kra, 'empevalpptwo'));//should return 4Array( [4] => Array ( [id] => 50 [user_id] => 6282 [specific_user_id] => 6281 [eval_cat_id] => 2 [format_cat] => 1 [title] => This istesting [desc] => [weight] => 50 [bsc_weight_group] => [bsc_rating] => [sequence] => [created_at] => 2019-05-22 10:55:23 [updated_at] => 2019-05-22 10:55:23 [kra] => Array ( [0] => Array ( [id] => 77 [user_id] => 6282 [bsc_id] => 50 [index] => 0 [kra_title] => ttes lang muna [kra_desc] => [kra_weight] => 25 [sat] => 521 [at] => 4 [ot] => 535 [rating_per_kra] => [rating_per_kra_cat] => [net_weighting] => 5 [rank] => 1 [remarks] => [indicator_text] => [created_at] => [updated_at] => [empevalpptwo] => ) ) ) ))
2 回答
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
类似于:
<?php
$items =
[
1 =>
[
'foo'=>
[
[
'bar' => '',
],
[
'bar' => '',
]
]
],
2 =>
[
'foo'=>
[
[
'bar' => 'baz'
]
]
]
];
foreach ($items as $k => $item)
if(empty(array_filter(array_column($item['foo'], 'bar'))))
unset($items[$k]);
var_export($items);
输出:
array (
2 =>
array (
'foo' =>
array (
0 =>
array (
'bar' => 'baz',
),
),
),
)
- 2 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消