3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'filesystem-2.4.0-1 comps-extras-11.1-1.1 gnome-mime-data-2.4.2-3.1 glibc-2.5-12 atk-1.12.2-1.fc6 libICE-1.0.1-2.1 db4-4.3.29-9.fc6 elfutils-libelf-0.125-3.el5 ncurses-5.5-24.20060715 libsepol-1.15.2-1.el5 libcap-1.10-26 sqlite-3.3.6-2 pcre-6.6-1.1 gdbm-1.8.0-26.2.1 libsepol-1.15.2-1.el5 libXdmcp-1.0.1-2.1 db4-4.3.29-9.fc6 iptables-1.3.5-1.2.1 libXrender-0.9.1-3.1 libXi-1.0.1-3.1 xorg-x11-font-utils-7.1-2 slang-2.0.6-4.el'; $array = explode(PHP_EOL, $str); array_walk($array, function(&$value, $key) { preg_match('/-\d/', $value, $match, PREG_OFFSET_CAPTURE); $offset = !empty($match) ? $match[0][1] : strlen($value); $value = [ 'name' => substr($value, 0, $offset), 'version' => trim(substr($value, $offset), '-') ]; }); print_r($array);

preferences:
32.9 ms | 409 KiB | 5 Q