I very new in yii as we use pluck() in laravel to get specific column value in a array how can i do same in yii.I am expecting values in array it return as different objects
*********My query **********
$get_coupon_ids=Coupon_categories::find()->select(['coupon_id'])->where(['in', 'category',$category_id])->all();
*****************************
*********OutPut****************
[
{
"coupon_id": 13
},
{
"coupon_id": 14
},
{
"coupon_id": 15
}
]
***************************************
*******Expected value *************
[13,14,15]
*********************************
You can use the column method, it will return the first column of each result. https://www.yiiframework.com/doc/api/2.0/yii-db-query#column()-detail
$get_coupon_ids = Coupon_categories::find()
->select(['coupon_id'])
->where(['in', 'category', $category_id])
->column();
or use array_map
$get_coupon_ids = Coupon_categories::find()
->select(['coupon_id'])
->where(['in', 'category', $category_id])
->all();
$ids = array_map(fn($id) => $id['coupon_id'], $get_coupon_ids);