3v4l.org

run code in 300+ PHP versions simultaneously
<?php $psr4 = array( 'my\\first\\ns\\prefix\\' => 0, 'my\\second\\ns\\prefix\\' => 0, 'my\\third\\ns\prefix' => 0, ); foreach ($psr4 as $prefix => &$v) { $v = strlen($prefix); } $classes = array( 'my\\third\\ns\\prefix\\subns\\class', 'another\\ns\\prefix\\subns\\class', ); foreach ($classes as $class) { foreach ($psr4 as $prefix => $length) { if (0 === strpos($class, $prefix)) { echo "$class -> $prefix\n"; break; } } } echo "-----------------------------\n"; foreach ($classes as $class) { foreach ($psr4 as $prefix => $length) { if (strncmp($class, $prefix, $length)) { echo "$class -> $prefix\n"; break; } } }
Output for git.master, git.master_jit, rfc.property-hooks
my\third\ns\prefix\subns\class -> my\third\ns\prefix ----------------------------- my\third\ns\prefix\subns\class -> my\first\ns\prefix\ another\ns\prefix\subns\class -> my\first\ns\prefix\

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