Article 58H64 Use bash variable in bash call to php function?

Use bash variable in bash call to php function?

by
buddy1234567
from LinuxQuestions.org on (#58H64)
Here is the situation:

I have a php script called testAddTwoNums-sol.php with a function called Calculator:

Code:<?php
//Add two numbers together
function Calculator($x, $y, $op) {
if($op == '+') {
$result = $x + $y;
}
}I'm attempting to pass values generated in bash to Calculator() like so:

Code:X=$[RANDOM%10+1]
Y=$[RANDOM%20+10]

# Addition
result=$(php -r "require 'testAddTwoNums-sol.php'; Calculator("X","Y",'+');")but it doesn't work. I get an error saying 'Warning: Use of undefined constant X - assumed 'X'

How can I pass X and Y from bash using the php cli (as I'm attempting to do above)?latest?d=yIl2AUoC8zA latest?i=yHlWRdO1z1U:tB5cy2ni4dw:F7zBnMy latest?i=yHlWRdO1z1U:tB5cy2ni4dw:V_sGLiP latest?d=qj6IDK7rITs latest?i=yHlWRdO1z1U:tB5cy2ni4dw:gIN9vFwyHlWRdO1z1U
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments