Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.3k
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);


2.8k

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);