3v4l.org

run code in 500+ PHP versions simultaneously
<?php $palettesString = 'someField;0'; $aPalettesArray = trimExplode(';', $palettesString); $aPalettesArray = [ 'fieldName' => $aPalettesArray[0], 'fieldLabel' => $aPalettesArray[1] ?: null, ]; var_dump($aPalettesArray['fieldLabel']); var_dump(!empty($aPalettesArray['fieldLabel'])); $bPalettesArray = trimExplode(';', $palettesString); $bPalettesArray = [ 'fieldName' => $bPalettesArray[0], 'fieldLabel' => $bPalettesArray[1] ?? null, ]; var_dump($bPalettesArray['fieldLabel']); var_dump(!empty($bPalettesArray['fieldLabel'])); function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0) { $result = explode($delim, $string) ?: []; if ($removeEmptyValues) { $temp = []; foreach ($result as $value) { if (trim($value) !== '') { $temp[] = $value; } } $result = $temp; } if ($limit > 0 && count($result) > $limit) { $lastElements = array_splice($result, $limit - 1); $result[] = implode($delim, $lastElements); } elseif ($limit < 0) { $result = array_slice($result, 0, $limit); } $result = array_map('trim', $result); return $result; }
Output for 8.3.6 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.12, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.4
NULL bool(false) string(1) "0" bool(false)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 NULL bool(false) string(1) "0" bool(false)

preferences:
18.15 ms | 1170 KiB | 6 Q