3v4l.org

run code in 300+ PHP versions simultaneously
<?php $find = "city"; $re = '/(' . $find . ')\":\s\"(.*?)\"|\"(\w+)\":\s\"(' . $find . ')/m'; $str = '{ "company": { "id": "123456", "name": "Test Company LLC.", "FEIN": "22-2222222", "address": { "address_line_1": { "street": "1 Street St, Suite 12", "city": "San Francisco", "postalCode": "123456" }, "address_line_2": { "state": "CA", "country": "USA" } }, "phone": "1-800-XXX-XXXX", "fax": "1-800-XXX-XXXX", "email": "admin@abc.com", "URL": "www.abc.com" }, "producer": { "id": "LLXXXX", "name": "Test Name", "phone": "555-555-5555", "mobile": "555-555-5555", "fax": "555-555-5555", "email": "test@abc.com", "producerSubCode": "111", "NIPRId": "123456", "stateProducerId": "12344" } }'; preg_match_all($re, $str, $matches); $result["value-match"] = array_slice(array_column($matches, 0),1,2); $result["key-match"] = array_slice(array_column($matches, 0),3,2); var_dump($result);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(2) { ["value-match"]=> array(2) { [0]=> string(4) "city" [1]=> string(13) "San Francisco" } ["key-match"]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(2) { ["value-match"]=> array(2) { [0]=> string(4) "city" [1]=> string(13) "San Francisco" } ["key-match"]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } }

preferences:
175.4 ms | 402 KiB | 199 Q