3v4l.org

run code in 300+ PHP versions simultaneously
<?php $creditScore = 'fair'; $ascending = true; $creditScores = array('excellent', 'good', 'fair', 'poor', 'no_credit'); if ($ascending) { $creditScores = array_flip($creditScores); } $position = array_search($creditScore, $creditScores); $acceptableCreditScores = array_slice($creditScores, $position); var_dump($acceptableCreditScores);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(5) { ["excellent"]=> int(0) ["good"]=> int(1) ["fair"]=> int(2) ["poor"]=> int(3) ["no_credit"]=> int(4) }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: array_slice() expects parameter 2 to be int, string given in /in/1SWmm on line 12 NULL
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
Warning: array_slice() expects parameter 2 to be integer, string given in /in/1SWmm on line 12 NULL
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Warning: array_slice() expects parameter 2 to be long, string given in /in/1SWmm on line 12 NULL

preferences:
180.05 ms | 402 KiB | 229 Q