<?php
function array_equal_set() {
return count(array_unique(array_map(function ($arr) {
$arr = array_unique($arr);
sort($arr);
return serialize($arr);
}, func_get_args()))) === 1;
}
$test_cases = array(
/* 0 */ array( 'A' , 'B' , 'C' ),
/* 1 */ array( 'A' , 'C' , 'B' ),
/* 2 */ array( 'B' , 'A' , 'C' ),
/* 3 */ array( 'B' , 'C' , 'A' ),
/* 4 */ array( 'C' , 'A' , 'B' ),
/* 5 */ array( 'C' , 'B' , 'A' ),
/* 6 */ array( 'A' , 'B' , 'C' , 'D' ),
/* 7 */ array( 'A' , 'B' , 'D' ),
/* 8 */ array( 'A' , 'B' , 'B' ),
/* 9 */ array( 'A' , 'B' ),
/* 10 */ array( 'A' , 'B' , 'C' , 'B' ),
);
// test
$data = array( 'A' , 'B' , 'C' );
foreach( $test_cases as $key => $test ){
$result = array_equal_set( $test, $data ) ? 'TRUE' : 'FALSE' ;
echo "[$key]$result" . PHP_EOL;
}
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- [0]TRUE
[1]TRUE
[2]TRUE
[3]TRUE
[4]TRUE
[5]TRUE
[6]FALSE
[7]FALSE
[8]FALSE
[9]FALSE
[10]TRUE
- Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
- Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/8lQV6 on line 4
Process exited with code 255. - Output for 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/8lQV6 on line 4
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error, expecting `')'' in /in/8lQV6 on line 4
Process exited with code 255. - Output for 4.3.0
- Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/U1dm9 on line 4
Process exited with code 255.
preferences:
235.9 ms | 401 KiB | 337 Q