fork(5) download
  1. <?php
  2.  
  3. $a = array(
  4. 'a' => NULL,
  5. 'b' => 1,
  6. 'c' => 1,
  7. 'd' => NULL
  8. );
  9.  
  10. $b = array(
  11. 'a' => 1,
  12. 'b' => NULL,
  13. 'c' => 1,
  14. 'd' => NULL,
  15. );
  16.  
  17. $c = array();
  18. foreach($a as $key => $val)
  19. {
  20. if($key == NULL && $b[$key] == NULL)
  21. {
  22. $c[$key] = $val;
  23. } else if($key != NULL && $b[$key] == NULL) {
  24. $c[$key]= $val;
  25. } else if($key != NULL && $b[$key] != NULL) {
  26. $c[$key]= $b[$key];
  27. } else {
  28. $c[$key]= $b[$key];
  29. }
  30. }
  31. var_dump($c);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
array(4) {
  ["a"]=>
  int(1)
  ["b"]=>
  int(1)
  ["c"]=>
  int(1)
  ["d"]=>
  NULL
}