3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = " Name: John Doe Address: 123 Main St Second Address: hola City: Chicago State: IL Zip: 60021 Name: Jane Smith Address: 123 State Ave City: Boston State: MA Zip: 02501 Name: John Doe Address: 123 Main St City: Chicago State: IL Zip: 60021"; preg_match_all('!(Name.*|Address.*|City.*|State.*|Zip.*)!', $string, $results); $records = $results[0]; $finalResults = []; $lastElement = "Zip"; foreach ($records as $record) { $result[] = $record; $recordArray = explode(":", $record); if ($recordArray[0] === $lastElement) { $finalResults[] = $result; $result = []; } } var_dump($finalResults);
Output for rfc.property-hooks, git.master, git.master_jit
array(3) { [0]=> array(6) { [0]=> string(14) "Name: John Doe" [1]=> string(20) "Address: 123 Main St" [2]=> string(13) "Address: hola" [3]=> string(13) "City: Chicago" [4]=> string(9) "State: IL" [5]=> string(10) "Zip: 60021" } [1]=> array(5) { [0]=> string(16) "Name: Jane Smith" [1]=> string(22) "Address: 123 State Ave" [2]=> string(12) "City: Boston" [3]=> string(9) "State: MA" [4]=> string(10) "Zip: 02501" } [2]=> array(5) { [0]=> string(14) "Name: John Doe" [1]=> string(20) "Address: 123 Main St" [2]=> string(13) "City: Chicago" [3]=> string(9) "State: IL" [4]=> string(10) "Zip: 60021" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.45 ms | 1893 KiB | 4 Q