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 ), );

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.10.0090.01016.67
8.5.00.0090.01319.81
8.4.150.0030.00014.05
8.4.140.0110.01117.62
8.4.130.0130.00717.78
8.4.120.0100.00920.57
8.4.110.0040.00522.80
8.4.100.0100.00817.59
8.4.90.0070.00520.47
8.4.80.0120.00818.78
8.4.70.0080.01318.73
8.4.60.0080.00920.42
8.4.50.0130.00820.58
8.4.40.0120.00917.62
8.4.30.0040.00420.57
8.4.20.0070.00419.38
8.4.10.0090.00619.45
8.3.280.0140.00718.50
8.3.270.0110.01016.81
8.3.260.0110.00816.63
8.3.250.0050.00318.94
8.3.240.0100.01016.55
8.3.230.0080.00916.49
8.3.220.0120.00618.86
8.3.210.0060.00216.82
8.3.200.0050.00616.55
8.3.190.0130.00817.10
8.3.180.0100.00819.00
8.3.170.0140.00618.99
8.3.160.0140.00416.87
8.3.150.0130.00716.55
8.3.140.0000.00816.54
8.3.130.0040.00418.34
8.3.120.0130.00318.92
8.3.110.0000.00816.78
8.3.100.0060.00324.06
8.3.90.0190.00324.06
8.3.80.0180.00524.06
8.3.70.0190.00524.06
8.3.60.0150.00824.06
8.3.50.0160.00924.06
8.3.40.0140.00924.06
8.3.30.0260.01024.06
8.3.20.0250.00424.06
8.3.10.0150.00624.06
8.3.00.0140.00524.06
8.2.290.0150.00418.98
8.2.280.0080.00218.27
8.2.270.0100.01016.55
8.2.260.0040.00717.22
8.2.250.0140.00417.05
8.2.240.0160.00317.10
8.2.230.0000.01420.94
8.2.220.0140.00724.06
8.2.210.0090.00924.06
8.2.200.0160.00324.06
8.2.190.0160.00424.06
8.2.180.0150.00624.06
8.2.170.0120.00824.06
8.2.160.0180.00324.06
8.2.150.0220.00024.06
8.2.140.0140.00824.06
8.2.130.0160.00624.06
8.2.120.0210.00024.06
8.2.110.0140.00624.06
8.2.100.0110.01124.06
8.2.90.0160.00424.06
8.2.80.0160.00424.06
8.2.70.0160.00324.06
8.2.60.0190.00324.06
8.2.50.0270.00724.06
8.2.40.0170.00924.06
8.2.30.0140.00724.06
8.2.20.0180.00024.06
8.2.10.0180.00024.06
8.2.00.0160.00324.06
8.1.330.0120.00721.86
8.1.320.0100.00918.25
8.1.310.0030.00616.47
8.1.300.0060.00317.68
8.1.290.0170.00324.06
8.1.280.0080.01624.06
8.1.270.0170.00624.06
8.1.260.0110.01124.06
8.1.250.0220.00024.06
8.1.240.0060.01224.06
8.1.230.0160.00324.06
8.1.220.0180.00024.06
8.1.210.0220.00324.06
8.1.200.0160.00424.06
8.1.190.0170.00324.06
8.1.180.0110.00824.06
8.1.170.0170.00024.06
8.1.160.0160.00324.06
8.1.150.0080.01224.06
8.1.140.0150.00624.06
8.1.130.0160.00424.06
8.1.120.0150.00624.06
8.1.110.0110.01124.06
8.1.100.0190.00024.06
8.1.90.0160.00524.06
8.1.80.0150.00724.06
8.1.70.0160.00424.06
8.1.60.0110.01124.06
8.1.50.0170.00424.06
8.1.40.0160.00524.06
8.1.30.0190.00624.06
8.1.20.0100.01024.06
8.1.10.0190.00024.06
8.1.00.0170.00324.06

preferences:
34.71 ms | 403 KiB | 5 Q