3v4l.org

run code in 300+ PHP versions simultaneously
<?php //---------------------------------- // array_unique() semi-replacements //---------------------------------- // @link http://php.net/manual/en/function.array-unique.php#98453 function wp_array_unique1( $arr = array() ) { $tmp = array(); foreach( $arr as $key => $val ) { $tmp[$val] = true; } return array_keys( $tmp ); } // @link http://www.puremango.co.uk/2010/06/fast-php-array_unique-for-removing-duplicates/#comment-202704 function wp_array_unique2( $arr = array() ) { $tempArray = array(); foreach($arr as $key => $val ) { if( isset( $tempArray[$val] ) ) continue; $tempArray[$val] = $key; } return array_flip($tempArray); } // @link http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip function wp_array_unique3( $arr = array() ) { // Code documented at: http://www.puremango.co.uk/?p=1039 return array_flip(array_flip(array_reverse($arr,true))); } // @link http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip function wp_array_unique4( $arr = array() ) { return array_keys( array_flip( $arr ) ); } // @link http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip function wp_array_unique5( $arr = array() ) { return array_flip( array_flip( $arr ) ); } //---------- // Input //---------- $input = array( 0 => 1, 1 => 2, 2 => 2, 3 => 0, 4 => -1, 5 => '1', 'a' => 'c', 'b' => 'a', 'c' => 'c' ); //------------------- // Test comparisions //------------------- echo 'Input:'; print_r( $input ); echo 'array_unique: '; print_r( array_unique( $input ) ); echo 'Replacement #1: '; print_r( wp_array_unique1( $input ) ); echo 'Replacement #2: '; print_r( wp_array_unique2( $input ) ); echo 'Replacement #3: '; print_r( wp_array_unique3( $input ) ); echo 'Replacement #4: '; print_r( wp_array_unique4( $input ) ); echo 'Replacement #5: '; print_r( wp_array_unique5( $input ) );
Output for git.master, git.master_jit, rfc.property-hooks
Input:Array ( [0] => 1 [1] => 2 [2] => 2 [3] => 0 [4] => -1 [5] => 1 [a] => c [b] => a [c] => c ) array_unique: Array ( [0] => 1 [1] => 2 [3] => 0 [4] => -1 [a] => c [b] => a ) Replacement #1: Array ( [0] => 1 [1] => 2 [2] => 0 [3] => -1 [4] => c [5] => a ) Replacement #2: Array ( [0] => 1 [1] => 2 [3] => 0 [4] => -1 [a] => c [b] => a ) Replacement #3: Array ( [a] => c [b] => a [0] => 1 [4] => -1 [3] => 0 [1] => 2 ) Replacement #4: Array ( [0] => 1 [1] => 2 [2] => 0 [3] => -1 [4] => c [5] => a ) Replacement #5: Array ( [5] => 1 [2] => 2 [3] => 0 [4] => -1 [c] => c [b] => a )

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:
56.59 ms | 407 KiB | 5 Q