Joining multiple functions data in one array This bit of code gathers data from two methods and puts it into an array. The code works fine but it doesn't look pretty and I feel like there is a better way of doing what I have done.

public static function RagUpdate()
{
    $MachineOnOffStatus = self::RagOnOffStatus();
    $ActiveMachine = array();
    foreach ($MachineOnOffStatus as $Key =&gt; $val) {
        if ($val['DateDifference'] &lt; 360) {
            $ActiveMachine[$val['controllerID']]['controllerID'] = $val['controllerID'];
            $ActiveMachine[$val['controllerID']]["DateDiff"] = $val['DateDifference'];
        }
    }

    foreach (self::ActiveMachineCycleTime($ActiveMachine) as $Key =&gt; $val) {
        foreach ($ActiveMachine as $k =&gt; $v) {
            if ($val["controllerID"] == $v["controllerID"]) {
                $ActiveMachine[$v['controllerID']]["CycleTime"] = $val['ElaspedTime'];
            }
        }
    }
    return $ActiveMachine;
}


Output of this method:




array (size=5)
2 =&gt; 
array (size=3)
  'controllerID' =&gt; string '2' (length=1)
  'DateDiff' =&gt; string '136' (length=3)
  'CycleTime' =&gt; string '-61' (length=3)
28 =&gt; 
array (size=3)
  'controllerID' =&gt; string '28' (length=2)
  'DateDiff' =&gt; string '129' (length=3)
  'CycleTime' =&gt; string '-52' (length=3)
30 =&gt; 
array (size=3)
  'controllerID' =&gt; string '30' (length=2)
  'DateDiff' =&gt; string '96' (length=2)
  'CycleTime' =&gt; string '-45' (length=3)
37 =&gt; 
array (size=3)
  'controllerID' =&gt; string '37' (length=2)
  'DateDiff' =&gt; string '123' (length=3)
  'CycleTime' =&gt; string '-69' (length=3)
40 =&gt; 
array (size=3)
  'controllerID' =&gt; string '40' (length=2)
  'DateDiff' =&gt; string '89' (length=2)
  'CycleTime' =&gt; string '-75' (length=3)
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.