Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Php check words are the same forward and backwards

I have seen this php function on stack overflow to check if a word is the same forward and backwards but I haven’t found any help on checking multiple words at once.
How to code the php so that it would display the code below as
Civic is a palindrome
Geography is not a palindrome
Great full of any help
Thanks

<?php
$arr = ('civic','geography');
$word =strtolower($arr);
$reverse=strrev($word); 
if ($word == $reverse) {
    echo "<p style='color:green;'>";
    echo " $word is a palindrome </p>";
} else {
    echo "<p style='color:red;'>";
    echo " $word is not a palindrome </p>";
}
?>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is your solution:

$arr = array('civic','geography');
foreach($arr as $word) {
    $word = strtolower($word);
    $reverse = strrev($word); 
    if ($word == $reverse) {
        echo "<p style='color:green;'>";
        echo " $word is a palindrome </p>";
    } else {
        echo "<p style='color:red;'>";
        echo " $word is not a palindrome </p>";
    }
}

I suggest you to read about loops

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading