3v4l.org

run code in 300+ PHP versions simultaneously
<?php $Old = array(array("Subject"=>"Informatik 1", "Active"=>"1")); //$New = array(array("Subject"=>"Informatik 1", "Active"=>"0", "Subject"=>"Informatik 2", "Active"=>"1")); $New = array("Informatik 1~0", "Informatik 2~1"); var_dump(MergeOfReqs($Old, $New)); function MergeOfReqs($Old, $New) { echo"----<br/>".print_r($Old, true)."<br/>--<br/>".print_r($New, true)."<br/>--<br/>"; foreach($Old as &$O) { echo print_r($O, true)."<br/>"; $State = OffReqState($O, $New); $O["Active"] = ($State !== false) ? $State : 2; } echo"<br/>--<br/>"; foreach($New as $N) { echo print_r($N, true)."<br/>"; if(OffReqState($N, $Old) === false) { $Old[] = $N; } } echo "<br/>--<br/>".print_r($Old, true)."<br/>"; echo"-----<br/><br/>"; return $Old; } //And another shitty/crappy name function OffReqState($Elem, $Array) { foreach($Array as $Element) { if(strcmp($Element["Subject"], $Elem["Subject"]) == 0) { return $Elem["Active"]; } } return false; }

preferences:
30.41 ms | 402 KiB | 5 Q