0

I need to pass a string (in command line as, php test.php dad) and check whether its a palindrome or not. I dont know how to pass string argumnet to a function. please explain, sample code is given below,

function Palindrome($string){  
    if (strrev($string) == $string){  
        return 1;  
    }
    else{
        return 0;
    }
}  
# I need to pass DAD as an argument in command line
$original = "DAD"; 
if(Palindrome($original)){  
    echo "Palindrome";  
} 
else {  
echo "Not a Palindrome";  
}
?>  
Sam
  • 77
  • 2
  • 8
  • 2
    Possible duplicate of [Pass variable to php script running from command line](https://stackoverflow.com/questions/6826718/pass-variable-to-php-script-running-from-command-line) – Yerke May 30 '18 at 03:59

1 Answers1

0

You can use variable $argv . For your case, it's $argv[1]

FoxVSky
  • 124
  • 5