Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing variables in if statements
    primarykey
    data
    text
    <p>PHP novice here. I searched for this, but i'm sure i'm not using the right syntax regarding my issue. Apologies then if this is a duplicate:</p> <p>I have these 3 variables:</p> <pre><code>$param = get_sub_field('custom_parameter'); $compare = get_sub_field('parameter_compare'); $param_val = get_sub_field('parameter_value'); </code></pre> <p>each one would return this:</p> <pre><code>$param is 'my_parameter' $compare is either '==', '&lt;=', or '=&gt;' $param_val is something like '5' or any value that the user sets </code></pre> <p>What i have is an editing interface where the user can set their parameter name, set the compare and then add the value. To that they can also add an action that occurs if the parameter matches. I'm using this in conjunction with $_GET.</p> <p>What i'd like to do is insert each variable from above into my if statement so the comparison is created by the user. However, it keeps giving me an error when i try to do this:</p> <pre><code>if($_GET[$param] $compare $param_val) { // do something } </code></pre> <p>The error i get is: </p> <blockquote> <p><strong>Parse error:</strong> syntax error, unexpected T_VARIABLE</p> </blockquote> <p>This of course works just fine:</p> <pre><code>if($_GET[$param] == $param_val) { // do something } </code></pre> <p>Hopefully i've explained this well enough and any help is greatly appreciated.</p> <p><strong>Update</strong>: Thank you for answering this for me and jumping on it so quickly. Learned a ton here!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload