title: How to write a program to concatenate two strings character by character. e.g : JOHN + SMITH = JSOMHINTH
body: <p>This is my code but it only gives results if both strings are of same length. But what if I want to compare strings of different lengths?</p>
  
  <pre><code>&lt;?php
  
    $n1 = "Apple";
    $n2 = "Orang";
  
    //count length fo both string 
    $count1 = strlen($n1);
    $count2 = strlen($n2);
    $finalcount = 0;
  
    if($count1 &gt; $count2) {
      $finalcount = $count1;
    } elseif ($count1 &lt; $count2) {
      $finalcount = $count2;
    } else {
      $finalcount = $count1;
    }
  
    //convert string to array
    $n1 = str_split($n1);
    $n2 = str_split($n2);
  
    $i = 0;
    $result = "";
    for($i = 0;$i &lt; $finalcount  ; $i++) {
      $result = $result .$n1[$i] . $n2[$i];
    }
  
    echo $result;
  ?&gt;
  </code></pre>