title: Using Ternary Operator without the Else statement PHP
body: <p>Can you use the Ternary Operator in PHP without the closing 'else' statement? I've tried it and it's returning errors. Google search isn't yielding anything, so I think the answer is probably no. I just wanted to double check here. For instance:</p>
  
  <pre><code>if ( isset($testing) {
    $new_variable = $testing;
  }
  </code></pre>
  
  <p>Will only set $new_variable if $testing exists. Now I can do </p>
  
  <pre><code>$new_variable = (isset($testing) ? $testing : "");
  </code></pre>
  
  <p>but that returns an empty variable for $new_variable if $testing isn't set. I don't want an empty variable if it's not set, I want the $new_variable to not be created.</p>
  
  <p>I tried</p>
  
  <pre><code>$new_variable = (isset($testing) ? $testing);
  </code></pre>
  
  <p>and it returned errors. I also tried</p>
  
  <pre><code>$new_variable = (isset($testing) ? $testing : );
  </code></pre>
  
  <p>and it also returned errors. Is there a way to use the Ternary Operator without the attached else statement, or am I stuck writing it out longhand?</p>
  
  <p>EDIT: Following Rizier123's advice, I tried setting the 'else' part of the equation to NULL, but it still ends up appending a key to an array. The value isn't there, but the key is, which messes up my plans. Please allow me to explain further.</p>
  
  <p>The code is going to take a bunch of $_POST variables from a form and use them for parameters in a stdClass which is then used for API method calls. Some of form variables will not exist, as they all get applied to the same variable for the API call, but the user can only select one. As an example, maybe you can select 3 items, whichever item you select gets passed to the stdClass and the other 2 don't exist. </p>
  
  <p>I tried this:</p>
  
  <pre><code>$yes_this_test = "IDK";
  $setforsure = "for sure";
  $list = new stdClass;
  $list-&gt;DefinitelySet = $setforsure;
  $list-&gt;MaybeSet = (isset($yes_this_test) ? $yes_this_test : NULL);
  $list-&gt;MaybeSet = (isset($testing) ? $testing : NULL);
  print_r($list);
  </code></pre>
  
  <p>But obviously MaybeSet gets set to NULL because (isset($testing) comes after (isset($yes_this_test) and it returns</p>
  
  <pre><code>stdClass Object ( [DefinitelySet] =&gt; for sure [MaybeSet] =&gt; )
  </code></pre>
  
  <p>I won't know what order the $_POST variables are coming in, so I can't really structure it in such a way to make sure the list gets processed in the correct order. </p>
  
  <p>Now I know I can do something like</p>
  
  <pre><code>if ( isset($yes_this_test ) {
    $list-&gt;MaybeSet = $yes_this_test;
  }
  elseif ( isset($testing) ) {
    $list-&gt;MaybeSet = $testing;
  }
  </code></pre>
  
  <p>But I was hoping there was a shorthand for this type of logic, as I have to write dozens of these. Is there an operator similar to the Ternary Operator used for if/elseif statements?</p>