3v4l.org

run code in 300+ PHP versions simultaneously
<?php // note the const declarations -- constants really read-only vars const COMMA = ','; const EMPTY_STR = ""; const NULL_CHAR = "\0"; $delim = '\n'; // note what happens when inserted into doubled-quoted string $data = "1,2,3,$delim,4,5,6,$delim,7,8,9"; echo "\nThe data is:\n\n$data\n\n"; var_dump( EMPTY_STR, NULL_CHAR,strcmp(EMPTY_STR, NULL_CHAR)); // "" != "\0" and "" !== "\0" echo "Is null char empty value? ",empty(NULL_CHAR)? 'true':'false',"\n"; echo "Is zero an empty value? ",empty(0)? 'true':'false',"\n"; $strNumsEtc = str_replace( COMMA, EMPTY_STR, $data); echo "\nResult: $strNumsEtc\n"; $strArr = explode( $delim, $strNumsEtc); var_dump(str_split($strNumsEtc,3)); foreach ($strArr as $str) { echo $str,PHP_EOL; // echo print both shades of echo: echo multiple vars, print one var plus retval } // must add the PHP_EOL since PHP doesn't automatically do this echo PHP_EOL; foreach ($strArr as $str) { print $str; print PHP_EOL; }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
The data is: 1,2,3,\n,4,5,6,\n,7,8,9 string(0) "" string(1) "" int(-1) Is null char empty value? false Is zero an empty value? true Result: 123\n456\n789 array(5) { [0]=> string(3) "123" [1]=> string(3) "\n4" [2]=> string(3) "56\" [3]=> string(3) "n78" [4]=> string(1) "9" } 123 456 789 123 456 789
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in /in/jAnf9 on line 13
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /in/jAnf9 on line 13
Process exited with code 255.
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_CONST in /in/jAnf9 on line 3
Process exited with code 255.
Output for 4.3.0 - 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_CONST in /in/jAnf9 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/jAnf9 on line 3
Process exited with code 255.

preferences:
357.35 ms | 401 KiB | 464 Q