手记

百度测试1,数组单词首位相同测试(php)

<?php
$test1 = ['abcd','defg','ghij','jkl'];
$test2 = ['abcd','defg','hij','kle'];
$ans = '';
function test($arrs){
$oldE = lastW($arrs[0]);
foreach($arrs as $word){
$len = strlen($word);
if($len<100 && $len >2){
$newF = $word{0};
if($newF == $oldE){
$oldE = lastW($word);
$ans = 1;
}else{
$ans = 0;
}
}else{
echo "err test info";
}
}
echo $ans;
}

function lastW($a){
$b = trim($a);
$len = strlen($b)-1;
$c = $b{$len};
return $c;
}
test($test1);
test($test2);

1人推荐
随时随地看视频
慕课网APP