3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_diff_assoc_recursive( ...$arrays ) { $i = \count( $arrays ); while ( --$i ) { $p = $i - 1; if ( \is_array( $arrays[ $i ] ) && \is_array( $arrays[ $p ] ) ) { foreach ( $arrays[ $i ] as $key => &$value ) { if ( ! \array_key_exists( $key, $arrays[ $p ] ) ) { // If the value doesn't exist in previous array, pass it along. $arrays[ $p ][ $key ] = $value; continue; } if ( $value === $arrays[ $p ][ $key ] || ( \is_array( $value ) && ! array_diff_assoc_recursive( ...array_column( $arrays, $key ) ) ) ) { // If there's no diff with the previous array or no diff can be found recursively, remove it from all the next arrays. foreach ( range( $p, $i ) as $_i ) if ( \is_array( $arrays[ $_i ] ) ) unset( $arrays[ $_i ][ $key ] ); continue; } } } } return $arrays[0]; } $array1 = array("a" => "green", "b" => "brown", "c" => "bluea" ); $array2 = array("a" => "green", "b" => "brown", "c" => "blue" ); var_dump( array_diff_assoc( $array1, $array2 ), array_diff_assoc_recursive( $array1, $array2 ), array_diff_assoc( $array1 ), array_diff_assoc_recursive( $array1 ), ); $a = [ 'one' => [ 1 => 'test', 2 => [ 'one', 'five', 'two', [ 'diff' => 'this', 'three' => 'four' ], ], ], 'two' => [ 1 => 'test2', 'two' => [ 'one', 'two', 'three' => 'four', 5, ], ], 'three', ]; $b = [ 'one' => [ 1 => 'test', 2 => [ 'one', 'five', 'two', [ 'three' => 'four', 'diff' => 'this' ], // 'one', 'two', [ 'diff' => 'this', 'three' => 'four' ], 'five', ], ], 'two' => [ 'two' => [ 'one', 'two', 5 => 4, 'three' => 'four', // 'one', 'two', 'three' => 'four', 5, ], 1 => 'test2', ], 'three', 'four', ]; var_dump( array_diff_assoc_recursive( $a, $b ), );
Output for git.master, git.master_jit, rfc.property-hooks
array(1) { ["c"]=> string(5) "bluea" } array(1) { ["c"]=> string(5) "bluea" } array(3) { ["a"]=> string(5) "green" ["b"]=> string(5) "brown" ["c"]=> string(5) "bluea" } array(3) { ["a"]=> string(5) "green" ["b"]=> string(5) "brown" ["c"]=> string(5) "bluea" } array(2) { ["two"]=> array(2) { [1]=> string(5) "test2" ["two"]=> array(4) { [0]=> string(3) "one" [1]=> string(3) "two" ["three"]=> string(4) "four" [2]=> int(5) } } [1]=> string(4) "four" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
45.89 ms | 407 KiB | 5 Q