- strpos: documentation ( source)
- 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',
);
foreach ($classes as $class) {
foreach ($psr4 as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
echo "$class -> $prefix\n";
break;
}
}
}
echo "-----------------------------\”";
foreach ($classes as $class) {
foreach ($psr4 as $prefix => $length) {
if (strncmp($class, $prefix, $length)) {
echo "$class -> $prefix\n";
break;
}
}
}