3v4l.org

run code in 300+ PHP versions simultaneously
<?php // $contentLines = file('path/to/content.txt'); $contentLines = [ 'Weight 229.6104534866 g', 'Energy 374.79170898476 kcal', 'Total lipid (fat) 22.163422468932 g', 'Carbohydrate, by difference 13.641848209743 g', 'Sugars, total 4.3691034101428 g', 'Protein 29.256342349938 g', 'Sodium, Na 468.99386390008 mg', ]; var_export( array_map( fn($line) => sscanf( $line, '%[^0-9] %f %s', ), $contentLines ) );
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 0 => array ( 0 => 'Weight ', 1 => 229.6104534866, 2 => 'g', ), 1 => array ( 0 => 'Energy ', 1 => 374.79170898476, 2 => 'kcal', ), 2 => array ( 0 => 'Total lipid (fat) ', 1 => 22.163422468932, 2 => 'g', ), 3 => array ( 0 => 'Carbohydrate, by difference ', 1 => 13.641848209743, 2 => 'g', ), 4 => array ( 0 => 'Sugars, total ', 1 => 4.3691034101428, 2 => 'g', ), 5 => array ( 0 => 'Protein ', 1 => 29.256342349938, 2 => 'g', ), 6 => array ( 0 => 'Sodium, Na ', 1 => 468.99386390008, 2 => 'mg', ), )

preferences:
87.11 ms | 1366 KiB | 4 Q