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

Merge two query result

How can I merge two query result?

Example: $res1 = User::find(''); $res2 = User::find(''); $res = merge($res1, $res2);

I don't want to use toArray() method to make the object to be array.



6.4k
Accepted
answer
edited Apr '15
<?php

$res1 = iterator_to_array(User::find('id < 100'));
$res2 = iterator_to_array(User::find('referrer_id < 100'));

$res = array_merge($res1, $res2);

If you want unique objects:

<?php

$res = array_unique(array_merge($res1, $res2), SORT_REGULAR);


6.9k

Thanks, it works!

<?php

$res1 = iterator_to_array(User::find('id < 100'));
$res2 = iterator_to_array(User::find('referrer_id < 100'));

$res = array_merge($res1, $res2);

If you want unique objects:

<?php

$res = array_unique(array_merge($res1, $res2), SORT_REGULAR);