利用PHP7新特性, 链式调用PHP自带函数, 进行数据处理
<?php
$arr = [
['id' => 1, 'name' =>'111'],
['id' => 2, 'name' =>'222'],
['id' => 3, 'name' =>'333'],
['id' => 4, 'name' =>'333'],
['id' => 5, 'name' =>''],
];
Data::ini($arr)
->array_column('name', 'id')
->array_filter()
->array_unique()
->count()
->strval()
->echo(); // 3
Data::ini($arr)
->array_column('name', 'id')
->array_filter()
->array_unique()
->json_encode()
->exit(); // {"1":"111","2":"222","3":"333"}
?>
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »