- strncmp: documentation ( source)
<?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',
);
for ($i = 0; $i < 1000; $i++) {
foreach ($classes as $class) {
foreach ($psr4 as $prefix => $length) {
if (!strncmp($class, $prefix, $length)) {
//echo "$class -> $prefix\n";
break;
}
}
}
}