以逗号分隔的输出yii2

时间:2018-05-31 08:20:58

标签: yii2

在用户表中,我为每个用户提供了mobileno列。在auth_assignment表中我有权限。我希望拥有autthoriation的所有用户都拥有所有移动设备' c_apo'。我想要的输出只是 - 7777777777,9999999999

我使用的查询是 -

$mobiletemp = User::find()->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id')->select('mobileno')->andWhere(['auth_assignment.item_name' => 'c_apo'])->asArray()->all();
$mobile = ArrayHelper::getColumn($mobiletemp, 'mobileno');
var_dump($mobile);

我得到的输出是 -

array(1) { [0]=> array(2) { [0]=> string(10) "9999999999" [1]=> string(10) "7777777777" } } 

2 个答案:

答案 0 :(得分:3)

$mobile = User::find()
->select('mobileno')
->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id')
->andWhere(['auth_assignment.item_name' => 'c_apo'])
->column();

$mobile = implode(",", $mobile);

答案 1 :(得分:0)

//Here is a possible solution 

public $exitingMember;//have to declare virtual field in model

$alreadyMember = TaskCrewEmployee::find()
->select('GROUP_CONCAT(tce_u_id) as exitingMember')
->where(['tce_ts_id'=>500])
->groupBy(['tce_ts_id'])
->one();