你可以使用
strcspn()
Find length of initial segment not matching mask
例如:
echo strcspn('aAple', 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ');
// prints '1' - the string starts with 1 character not in upper case
完整代码
echo "
" ;
$array = array("aPple", "Orange", "baNana", "mANgo", "Papaya");
foreach($array as $value)
{
echo $value , "= " , strcspn($value, 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ') . PHP_EOL;
}
产量
aPple= 1
Orange= 0
baNana= 2
mANgo= 1
Papaya= 0
您可以使用该功能进行(反向)排序.