Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Test array_diff_assoc() function : usage variations - arrays containing reference..

Decoded Output download

*** Testing array_diff_assoc() : usage variations ***
-- Results when \$a = a: --

Did this file decode correctly?

Original Code

--TEST--
Test array_diff_assoc() function : usage variations - arrays containing referenced variables
--FILE--
<?php
/*
 * Tests how array_diff_assoc compares
 * 1. Referenced variables
 * 2. Arrays that have been referenced to each other
 */

echo "*** Testing array_diff_assoc() : usage variations ***\n";

$a = 'a';

$arr1 = array('a', 'b', 'c', $a);
$arr2 = array('a' => 1, 'b' => 2, 'c' => 3, &$a);

echo "-- Results when \$a = $a: --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));

$a = 4;

echo "-- Results when \$a has been changed to $a: --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));

$arr2 = &$arr1;

echo "-- Results when \$arr2 is referenced to \$arr1 --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));

$arr1 = array('zero' => 'x', 'one' => 'y', 'two' => 'z');

echo "-- Results when \$arr1 is changed --\n";
var_dump(array_diff_assoc($arr1, $arr2));
var_dump(array_diff_assoc($arr2, $arr1));

echo "Done";
?>
--EXPECT--
*** Testing array_diff_assoc() : usage variations ***
-- Results when $a = a: --
array(3) {
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
  [3]=>
  string(1) "a"
}
array(3) {
  ["a"]=>
  int(1)
  ["b"]=>
  int(2)
  ["c"]=>
  int(3)
}
-- Results when $a has been changed to 4: --
array(4) {
  [0]=>
  string(1) "a"
  [1]=>
  string(1) "b"
  [2]=>
  string(1) "c"
  [3]=>
  string(1) "a"
}
array(4) {
  ["a"]=>
  int(1)
  ["b"]=>
  int(2)
  ["c"]=>
  int(3)
  [0]=>
  &int(4)
}
-- Results when $arr2 is referenced to $arr1 --
array(0) {
}
array(0) {
}
-- Results when $arr1 is changed --
array(0) {
}
array(0) {
}
Done

Function Calls

array_diff_assoc 1

Variables

$a a
$arr1 [{'key': 0, 'value': 'a'}, {'key': 1, 'value': 'b'}, {'key': 2, 'value': 'c'}, {'key': 3, 'value': 'a'}]
$arr2 [{'key': 'a', 'value': 1}, {'key': 'b', 'value': 2}, {'key': 'c', 'value': 3}, {'key': 3, 'value': 'a'}]

Stats

MD5 abf873845662e06431f329ebd4c534d9
Eval Count 0
Decode Time 95 ms