[ create a new paste ] login | about

Link: http://codepad.org/2UtrPE3o    [ raw code | output | fork ]

PHP, pasted on Mar 18:
<?
$age = array("Peter"=>"35","Ben"=>"37","Joe"=>"");
$age2 = array("Peter"=>"38","Ben"=>"37","Joe"=>"43");

$result = array();
foreach($age as $key=>$val) {
  if (array_key_exists($key, $age2)) {
    if ($val!==$age2[$key])
      $result[$key] = 'Changed from '.(empty($val)?'blank':$val).' to '. (empty($age2[$key])?'blanc':$age2[$key]);
  } else {
    $result[$key] = 'Changed from '.(empty($val)?'blank':$val).' to blank';
  }
}

foreach($age2 as $key=>$val) {
  if (!array_key_exists($key, $age)) {
    $result[$key] = 'Changed from blank to ' . $val;
  }
}

var_dump($result);
?>


Output:
1
2
3
4
5
6
array(2) {
  ["Peter"]=>
  string(21) "Changed from 35 to 38"
  ["Joe"]=>
  string(24) "Changed from blank to 43"
}


Create a new paste based on this one


Comments: