Friday, May 22, 2015

Palindrome solution for php

In this tutorial i created an function that will tell if a given word is palindrome or not
 
 palindrome2('axa');
 function palindrome2($input){ 
    $split = str_split($input); //make the input array
    $count = strlen($input) - 1;//minus 1 bec array start at 0
    for($x=$count;$x >= 0;$x--){
      $newChar .= $split[$x]; //append the letters
    }  
    if($input === $newChar){
      echo "Palindrome";
    }else{
      echo "Not Palindrome";
    }
 }
the result will look like this
Palindrome
note that "axa" is the word that i want to check if it is palindrome or not, you can change it to the one you desired to check.

No comments:

Post a Comment