title: How to Assign true condition's value to a variable outside of if else condition in laravel?
body: <p>I am trying to assign some value to a variable named <code>$bonus</code> in if-else conditions and then I am trying to call <code>$bonus</code> outside of the if-else condition so the true condition's variable should be called automatically. I have tried this code but it is giving me an error on debugging mode of laravel</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Undefined variable: bonus</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  if ($data-&gt;lend_amount &gt;= 50 &amp;&amp; $data-&gt;lend_amount &lt;= 500) {
      $bonus = ($data-&gt;lend_amount * 4) / 100;
  } else if ($data-&gt;lend_amount &gt;= 500 &amp;&amp; $data-&gt;lend_amount &lt;= 50000) {
      $bonus = ($data-&gt;lend_amount * 5) / 100;
  }
  
  if ($user_b_update) {
      Transaction::create([
          'user_id' =&gt; $data-&gt;user_id,
          'trans_id' =&gt; rand(),
          'time' =&gt; Carbon::now(),
          'description' =&gt; 'Matching Bonus Of ' . $bvp . ' Users',
          'amount' =&gt; $bonus,
          'new_balance' =&gt; $newacc_bal,
          'new_earning' =&gt; $newbal,
          'type' =&gt; 4,
          'charge' =&gt; 0
      ]);
  }
  </code></pre>