3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json1 = '{ "d": [{"A": 0,"B": "foo1","C": "bar1","D": "real1","E": 0}, {"A": 1,"B": "foo2","C": "bar2","D": "real2","E": 1}, {"A": 2,"B": "foo3","C": "bar3","D": "real3","E": 2} ] }'; $json2 = '{ "A": ["this1","this2","this3"], "E": ["last1","last2","last3"] }'; $array1 = json_decode($json1, true); $array2 = json_decode($json2, true); foreach ($array1['d'] as &$arr) { foreach ($arr as $key => &$value) { if (array_key_exists($key, $array2)) { $value = $array2[$key][$value]; } } } echo json_encode($array1, JSON_PRETTY_PRINT);
Output for 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
{ "d": [ { "A": "this1", "B": "foo1", "C": "bar1", "D": "real1", "E": "last1" }, { "A": "this2", "B": "foo2", "C": "bar2", "D": "real2", "E": "last2" }, { "A": "this3", "B": "foo3", "C": "bar3", "D": "real3", "E": "last3" } ] }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
190.27 ms | 407 KiB | 5 Q