If..else loop and array does not follow condition for php : I had problem with this particular code. The conditions are:

~When `$rows['Machine#']` is not in array, push in `$machineArr` array and unset the `$totalTimeArr` array.

~When `$rows['Machine#']` is in the array, push `$rows['TotalTime']` into `$totalTimeArr` array for addition.

~`$graphArr[]` should be updated (for `array_sum($totalTimeArr)`) first before push into array.

I now have problems regarding the third condition. It does not calculate first, instead it pushes the first data input. I have tried using `do while` loop, putting `$graphArr[] = '["'.$rows['Machine#'].'",'.array_sum($totalTimeArr).']';` outside the `if else` loop, but this seems to be the closest I can get to what its supposed to be. Other codes doesnt seem to have problems and work well. Appreciate your recommendations/suggestions/assistance. Thanks. Below is the code.




    while ($rows = mysqli_fetch_array($conn))
    	{
    		if(!(in_array($rows['Machine#'], $machineArr)))
    		{
    			unset($totalTimeArr);
    			$machineArr[] = $rows['Machine#'];
    			$totalTimeArr[] = $rows['TotalTime'];
    			$graphArr[] = '["'.$rows['Machine#'].'",'.array_sum($totalTimeArr).']';
    		}
    		else if(in_array($rows['Machine#'], $machineArr))
    		{
    			$totalTimeArr[] = $rows['TotalTime'];
    		}
    	}