3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class testAPI { private array $employee; private array $template; /** * testAPI constructor. * @param array $employee – массив с данными о работнике * @param array $template — массив с шаблонами */ public function __construct(array $employee, array $template) { $this->employee = $employee; $this->template = $template; } public function getApiPath(): array { return preg_replace_callback( '#%(.*)%#isU', function (array $matches) { return $this->employee[$matches[1]]; }, $this->template ); } } $apiTemplatesSet1 = [ '/api/items/%id%/%name%', '/api/items/%id%/%role%', '/api/items/%id%/%salary%' ]; $user = [ 'id' => 20, 'name' => 'John Dow', 'role' => 'QA', 'salary' => 100 ]; $test = new testAPI($user, $apiTemplatesSet1); echo '<pre>' . print_r($test->getApiPath(), true) . '</pre>';
Output for git.master, git.master_jit, rfc.property-hooks
<pre>Array ( [0] => /api/items/20/John Dow [1] => /api/items/20/QA [2] => /api/items/20/100 ) </pre>

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