So I have something like the following:
$a = 3; $b = 4; $c = 5; $d = 6;
and I run a comparison like
if($a>$b || $c>$d) { echo 'yes'; };
That all works just fine. Is it possible to use a variable in place of the operator? Something like:
$e = ||;
Which I could then use as
if($a>$b $e $c>$d) { echo 'yes'; };
Assignment Operators are used to assign a value to a property or variable. Assignment Operators can be numeric, date, system, time, or text. Comparison Operators are used to perform comparisons. Concatenation Operators are used to combine strings.
JavaScript Assignment OperatorsAssignment operators assign values to JavaScript variables. The addition assignment operator ( += ) adds a value to a variable.
This chapter describes how to write statements using variables, which store values like numbers and words, and operators, which are symbols that perform a computation.
The increment (++) and decrement (--) operators are unusual in that you can place them either before or after the variable. Placing the operator symbol before the variable is called the prefix form of the operator, and using the operator symbol after the variable is called the postfix form.
No, that syntax isn't available. The best you could do would be an eval(), which would not be recommended, especially if the $e came from user input (ie, a form), or a switch statement with each operator as a case
switch($e) { case "||": if($a>$b || $c>$d) echo 'yes'; break; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With