I have an associative array stored in a variable like so
$result = Array (
[0] => stdClass Object ( [user_id] => 3 [zone_id] => -1 )
[1] => stdClass Object ( [user_id] => 3 [zone_id] => 0 )
[2] => stdClass Object ( [user_id] => 3 [zone_id] => 2 )
[3] => stdClass Object ( [user_id] => 3 [zone_id] => 3 )
[4] => stdClass Object ( [user_id] => 3 [zone_id] => 4 )
[5] => stdClass Object ( [user_id] => 4 [zone_id] => 0 )
[6] => stdClass Object ( [user_id] => 4 [zone_id] => 2 )
[7] => stdClass Object ( [user_id] => 4 [zone_id] => 4 )
[8] => stdClass Object ( [user_id] => 4 [zone_id] => 5 )
[9] => stdClass Object ( [user_id] => 4 [zone_id] => 7 ))
I would like to convert this to an array that looks more like this
$newResult = array(
[0] => stdClass Object ( [user_id] => 3 [zone_id] => "-1;0;1;2;3;4" )
[1] => stdClass Object ( [user_id] => 3 [zone_id] => "0;2;4;5;7" ))
I tried using this post as a reference, but ran into trouble along the way. When I simply replaced the variables with mine I received this error
[Thu Oct 09 15:21:29 2014] [error] [client xxx.xxx.xx.xx] PHP Fatal error: Cannot use object of type stdClass as array in index.php on line 38
When I converted $n['zone_id']
to $n->zone_id
There were zero errors, but the zone_id(s) seemed to cycle through and repeat forever.
The kicker is that I also need to ignore any digits outside of the 0-9 range (like -1 and 10 for instance).
Any insights into this? I feel like it should be much easier to solve!
Thanks.