二维数组中取某一相同字段的值进行,拼接字符串

使用PHP自带的一个函数:array_column() ,该函数的作用是返回输入数组中某个单一列的值。

$firms = M('lawfirm')->where('status=1')->field('id')->select();
$firmids = array_column($firms, 'id');
$who = implode(',', $firmids);

或是通过foreach进行拼装。

Tags: PHP

添加新评论