title: Easy way to avoid string addition in php
body: <p>This question is an extension of the question asked here - <a href="https://stackoverflow.com/questions/72800332/easy-way-to-avoid-string-addition-in-c-sharp">Easy way to avoid string addition in C#</a>. I am looking for similar method to achieve in PHP.</p>
  <p>Problem: I have couple of string variables that sometimes have text and other times have integers in them. How do I add these variables when they are integers?</p>
  <p>Example:</p>
  <pre><code>&lt;?php
  
  $val1 = &quot;1&quot;;
  $val2 = &quot;2&quot;;
  $val3 = &quot;3&quot;;
  $val4 = &quot;k.A&quot;;
  $val5 = &quot;k.A&quot;;
  $val6 = &quot;5&quot;;
  
  $total = $val1 + $val2 + $val3 + $val4 + $val5 + $val6;
  
  ?&gt;
  </code></pre>
  <p>I know the above code will fail because val4 and val5 are strings, what I am looking for is it should avoid adding the above 2 strings and the total should be 11. I can check if the string is an integer or a text but that would take forever if the script I am working on does not have strings as an array. What is the right and easy way to do this?</p>