I have been trying to figure this out for a long time now and it’s got to
be something simple but I just can’t do it. Would someone please give me
a hand.
I have a php array that looks like this…
Array (
[0]
=> stdClass Object ( [_id] => 554ee2aee4b0766af041cdc5
[authorized_by] => free [bytes] => 45613 [name] =>
7a1b7bd4af6ca234 [port] => aa:bb:cc:dd:ee:ff )
[1] => stdClass
Object ( [_id] => 554e9346e4b0766af041cba9 [authorized_by] => pay
[bytes] => 94055684 [port] => 11:22:33:44:55:66 )
[2] =>
stdClass Object ( [_id] => 554ee2aee4b0766af041cdc5 [authorized_by]
=> free [bytes] => 67432148 [name] => b7bd7a14a234f6ca [port]
=> 11:bb:33:dd:55:ff )
[3] => stdClass Object ( [_id] =>
554e79d3e4b0766af041cb05 [authorized_by] => api [bytes] => 376235
[name] => 14ad7a326cab7b4f [port] => aa:22:cc:44:ee:66 )
)
How can I get it to select all the entries that are “[authorized_by] => free”
Then execute for each one that it finds
$seeya = $byebye->kick($port);
So in the above example it would do this…
$seeya = $byebye->kick(aa:bb:cc:dd:ee:ff);
$seeya = $byebye->kick(11:bb:33:dd:55:ff);
Thanks alot!
Maybe this might get you heading in the right direction.
Scott
Thank you for the reply.
Unless I’m missing something the only thing that I seem to get out of that is turning the array into stdClass Object.
stdClass Object (
[0] => stdClass Object ( [_id] => 554ee2aee4b0766af041cdc5 [authorized_by] => free [bytes] => 45613 [name] => 7a1b7bd4af6ca234 [port] => aa:bb:cc:dd:ee:ff )
[1] => stdClass Object ( [_id] => 554e9346e4b0766af041cba9 [authorized_by] => pay [bytes] => 94055684 [port] => 11:22:33:44:55:66 )
[2] => stdClass Object ( [_id] => 554ee2aee4b0766af041cdc5 [authorized_by] => free [bytes] => 67432148 [name] => b7bd7a14a234f6ca [port] => 11:bb:33:dd:55:ff )
[3] => stdClass Object ( [_id] => 554e79d3e4b0766af041cb05 [authorized_by] => api [bytes] => 376235 [name] => 14ad7a326cab7b4f [port] => aa:22:cc:44:ee:66 )
)
Thanks
Jason
foreach($originalArray as $object){
if ($object->authorized_by == 'free'){
$seeya = $byebye->kick($object->port);
}
}
1 Like
Are you joking me it was that easy!
Well going to go find a rocking claim under it now…
Thanks a lot @megazoid
My thinking was the other way around. Changing the objects in your array to arrays, in order to manipulate the whole array easier as a multidimensional array. Of course, megazoid’s solution is the simplest and easiest and much better though.
Scott
system
Closed
August 10, 2015, 12:47pm
7
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.