Reformat Multi-dimensional Associative Array

Hi, looking for some help to reformat a mutli-dimensional associate array that is returned from the COM function ExecQuery, specifically processess.

$comobj = new COM (“winmgmts:\\.\root\cimv2”);
$processes = $comobj->ExecQuery(“select * from Win32_Process”);

I can go through $processes in a foreach loop and get all the elements if I refer to each key (ie…handle, caption, etc…), but I would like to be able to reformat the contents of the array to a string without having to specify each key.

I’ve tried nested foreach loops, implode, etc…they all seem to hang up on the format of the array for some reason.

Has anyone attempted this before or have any suggestions to help get through this array without having to specifically name each key?

Thanks,

Scott

json_encode()

Hi, tried encode_json as well…no luck.

[php]$comobj = new COM (“winmgmts:\\.\root\cimv2”);
$processes = $comobj->ExecQuery(“select * from Win32_Process”);
echo json_encode($processes);[/php]

Output is empty: {}

Also tried to encode each process individually…

[php]$comobj = new COM (“winmgmts:\\.\root\cimv2”);
$processes = $comobj->ExecQuery(“select * from Win32_Process”);
foreach($processes as $process) {
echo json_encode($process);
}[/php]

Output is essentially empty for each process: {}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}

Then I would wonder if the query is always working. Json_encode makes arrays into strings. So, if there isnt a string, there isnt an array.

Sponsor our Newsletter | Privacy Policy | Terms of Service