//palindrom cara cepat
$word = abcfcba;
if ($word == strrev ($word)) {
echo 'The word is a palindrome';
} else {
echo 'This is not a palindrome';
}
//palindrom array
$arr = array('a','h','a');
if(count($arr) % 2) {
$stopat = ((count($arr) - 1) / 2) - 1;
} else {
$stopat = count($arr) / 2;
}
echo "
". $stopat;
$ispalarr = 0;
for($i = 0; $i < $stopat; $i++) {
if($arr[$i] == $arr[count($arr) - ($i + 1)]) {
echo "
masuk ke for";
$ispalarr = 1;
}
}
echo "
". $ispalarr;
echo "
";
if($ispalarr == 0) {
echo " The array is not a palindrome array.";
} else {
echo "The array is a palindrome array.";
}
?>
Rabu, Februari 11, 2009
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar