I’ve got a question. I’m building an array by getting data from mysql and merging three query results in one array.
I put data to array like this:
while ($a = mysql_fetch_object($activities)) {
$a->type = 1;
$array1[] = $a;
}
while ($k = mysql_fetch_object($fuups)) {
$k->type = 2;
$array1[] = $k;
}
while ($x = mysql_fetch_object($refuups)) {
$x->type = 3;
$array1[] = $x;
}
return (object)$array1;
This returns something like this:
stdClass Object
(
[0] => stdClass Object
(
[added] => 2012-01-17 07:33:53
[type] => 1
)
[1] => stdClass Object
(
[added] => 2012-01-13 06:36:22
[type] => 1
)
[2] => stdClass Object
(
[added_type_2] => 2012-01-09 04:01:12
[type] => 2
)
[3] => stdClass Object
(
[added_type_2] => 2012-02-08 02:08:32
[type] => 2
)
[4] => stdClass Object
(
[added_type_2] => 2012-01-25 00:09:08
[type] => 2
)
[5] => stdClass Object
(
[added_type_3] => 2012-01-23 00:09:08
[type] => 3
)
[6] => stdClass Object
(
[added_type_3] => 2012-01-22 00:09:08
[type] => 3
)
)
I tried things like asort, ksort, sort but no luck. also getting the dates with “order by added desc” thank you
You can use usort() if you change fetch object to fetch assoc:
Good luck…