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_all($pat, $str, $match); $merged = $original; $i = 0; foreach($match[1] as $result) { $merged[] = array("title" => $match[1][$i], "color" => $match[2][$i]); $i++; } print_r($merged);
Output for 4.3.0 - 7.1.0
Array ( [0] => Array ( [title] => one [color] => blue ) [1] => Array ( [title] => two [color] => green ) [2] => Array ( [title] => three [color] => red ) [3] => Array ( [title] => four [color] => white ) [4] => Array ( [title] => five [color] => black ) )