3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = '123.animal=cat 123.name=fred 123.food=fish 345.animal=dog petshop=zoonoria'; $ini = parse_ini_string($data); $result = []; foreach ($ini as $key => $value) { echo $key, ' => ', $value, PHP_EOL; $splitKey = explode('.', $key); $iniPtr = &$result; foreach($splitKey as $subKey) { if (!isset($iniPtr[$subKey])) { $iniPtr[$subKey] = null; } $iniPtr = &$iniPtr[$subKey]; } $iniPtr = $value; unset($iniPtr); } var_dump($result);
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
123.animal => cat 123.name => fred 123.food => fish 345.animal => dog petshop => zoonoria array(3) { [123]=> array(3) { ["animal"]=> string(3) "cat" ["name"]=> string(4) "fred" ["food"]=> string(4) "fish" } [345]=> array(1) { ["animal"]=> string(3) "dog" } ["petshop"]=> string(8) "zoonoria" }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
182.41 ms | 407 KiB | 5 Q