PHP typecasting null or int
<p>I want to let a variable be an int unless the variable is null.<br>
This is the way I fixed it atm but there's got to be a better solution.</p>

<pre><code>if ($answer == null) {
      $all_questions[] = array (
        'object_id'     =&gt; (int) $stored_question-&gt;getObjectId(),
        'question_code' =&gt; $stored_question-&gt;getQuestionCode(),
        'answer'        =&gt; $stored_question-&gt;getAnswer()
      );
    }
    else{
      $all_questions[] = array (
        'object_id'     =&gt; (int) $stored_question-&gt;getObjectId(),
        'question_code' =&gt; $stored_question-&gt;getQuestionCode(),
        'answer'        =&gt; (int) $stored_question-&gt;getAnswer()
      );
</code></pre>

<p>At least I hope there is because this seems redundant.</p>