We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

List of ids using the model

Is there a direct way to produce an array of ids ([1,2,3,4....]) using the model?

Could you explain what you want with more detail?

Are you talking about something like this: https://docs.phalcon.io/en/latest/api/Phalcon_Db_Result_Pdo.html

Instead of (SELECT * FROM ....) perhaps (SELECT id FROM ...)



1.8k
edited Apr '15

@ShadMickelberry, thanks but I was not referring to columns. When we use Users::find(['columns'=>'id'])->toArray() it produces:

array(3) {
  [0]=>
  array(1) {
    ["id"]=>
    string(1) "1"
  }
  [1]=>
  array(1) {
    ["id"]=>
    string(1) "2"
  }
  [2]=>
  array(1) {
    ["id"]=>
    string(1) "3"
  }
}

Is there a way that the output is like this

array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "3"
}

Please use code formatting - it's much easier to read. I've updated your last post.

To the best of my knowledge, there is no way using the ORM to get an array like what you want. However, array_walk() could probably be applied pretty easily.