3v4l.org

run code in 300+ PHP versions simultaneously
<?php class KeysReplacer { public $default = [ 'id' => 'id', 'full_address' => 'adress', 'floorall' => 'floorall', 'build_year' => 'build_year', ]; public $services = [ 'service_1' => [ 'id' => 'internal_id', 'full_address' => 'locality', 'floorall' => 'floorall', 'build_year' => 'build_date' ], 'service_2' => [ 'id' => 'ид', 'full_address' => 'полный_адрес', 'floorall' => 'этажность', 'build_year' => 'год_постройки' ], ]; public function __invoke($item, $from = null) { $result = []; foreach($item as $key => $value){ $result[$from && isset($this->services[$from][$key]) ? $this->services[$from][$key] : $this->default[$key]] = $value; } return json_encode($result, JSON_UNESCAPED_UNICODE); } } function getItem(){ return [ 'id' => 1, 'full_address' => 'г. Москва', 'floorall' => 18, 'build_year' => 1990 ]; } $item = getItem(); $responseNormalizer = new KeysReplacer; $response_0 = $responseNormalizer($item); $response_1 = $responseNormalizer($item, 'service_1'); $response_2 = $responseNormalizer($item, 'service_2'); var_dump($response_0); // string(68) "{"id":1,"adress":"г. Москва","floorall":18,"build_year":1990}" var_dump($response_1); // string(79) "{"internal_id":1,"locality":"г. Москва","floorall":18,"build_date":1990}" var_dump($response_2); // string(112) "{"ид":1,"полный_адрес":"г. Москва","этажность":18,"год_постройки":1990}"
Output for git.master, git.master_jit, rfc.property-hooks
string(68) "{"id":1,"adress":"г. Москва","floorall":18,"build_year":1990}" string(79) "{"internal_id":1,"locality":"г. Москва","floorall":18,"build_date":1990}" string(112) "{"ид":1,"полный_адрес":"г. Москва","этажность":18,"год_постройки":1990}"

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:
61.43 ms | 401 KiB | 8 Q