Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
How to get yii select query values as array

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]

*********************************
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!