百度測試1,陣列單詞首位相同測試(php)

Jack2k發表於2021-09-09

$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($len2){
$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);

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/36/viewspace-2798038/,如需轉載,請註明出處,否則將追究法律責任。

相關文章