3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $str = 'NAME OF ITEM 123456789012 OTHER NAME 987654321098 NAME 567890123456'; preg_match_all( '/^(.*?)\s+(\d+)$/m', $str, $matches); var_dump( $matches); $items = array(); foreach( $matches[2] as $k => $upc) { $items[$upc] = $matches[1][$k]; } var_dump( $items);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> array(3) { [0]=> string(25) "NAME OF ITEM 123456789012" [1]=> string(29) " OTHER NAME 987654321098" [2]=> string(29) " NAME 567890123456" } [1]=> array(3) { [0]=> string(12) "NAME OF ITEM" [1]=> string(14) " OTHER NAME" [2]=> string(8) " NAME" } [2]=> array(3) { [0]=> string(12) "123456789012" [1]=> string(12) "987654321098" [2]=> string(12) "567890123456" } } array(3) { [123456789012]=> string(12) "NAME OF ITEM" [987654321098]=> string(14) " OTHER NAME" [567890123456]=> string(8) " NAME" }