3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $original = array ( array ("title" => "one", "color" => "blue" ), array ("title" => "two", "color" => "green" ) ); $merged = array(); $str = "000three000red0!000four000white0!000five000black0!"; $pat = "/\d+(\D+)\d+(\D+)\d!/um"; preg_match($pat, $str, $match); foreach($match as $result) { $merged = array_merge($original,array("title" => $match[1], "color" => $match[2])); print_r($merged); }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [title] => one [color] => blue ) [1] => Array ( [title] => two [color] => green ) [title] => three [color] => red ) Array ( [0] => Array ( [title] => one [color] => blue ) [1] => Array ( [title] => two [color] => green ) [title] => three [color] => red ) Array ( [0] => Array ( [title] => one [color] => blue ) [1] => Array ( [title] => two [color] => green ) [title] => three [color] => red )