Joining multiple functions data in one array
I see some redundancy right off the bat:

$ActiveMachine[$val['controllerID']]['controllerID'] = $val['controllerID'];


If the key is the controllerID, do you need a separate controllerID underneath of it?  I would suspect not. You can use the $Key in place of $val['controllerID'] in the foreach below it.

As for the rest, do you have control over the output of the functions you are using?  Can the key of those arrays be used in a smarter way?  You are using $Key =&gt; $val, but you don't use $Key once.