title: Compare values of two multidimentional array and insert if not exits
body: <p>I have two array <code>$array1</code> and <code>$array2</code> which I get dynamically and look like </p>
  
  <pre><code>$array1 = Array
      (
          [0] =&gt; Array
              (
                  [hour] =&gt; 10
                  [activity] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [activity_id] =&gt; 1
                                  [cnt] =&gt; 2
                              )
                          [1] =&gt; Array
                              (
                                  [activity_id] =&gt; 2
                                  [cnt] =&gt; 1
                              )
                      )
              )
          [1] =&gt; Array
              (
                  [hour] =&gt; 11
                  [activity] =&gt; Array
                      (
                      )
              )
          [2] =&gt; Array
              (
                  [hour] =&gt; 12
                  [percentage] =&gt; 0
                  [activity] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [activity_id] =&gt; 2
                                  [cnt] =&gt; 5
                              )
                          [1] =&gt; Array
                              (
                                  [activity_id] =&gt; 3
                                  [cnt] =&gt; 2
                              )
                      )
              )
      );
  
  
  $array2 = Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 1
                  [name] =&gt; Phone Calls
                  [readable] =&gt; 1
                  [status] =&gt; active
              )
          [1] =&gt; Array
              (
                  [id] =&gt; 2
                  [name] =&gt; Meeting With Customer
                  [readable] =&gt; 1
                  [status] =&gt; active
              )
          [2] =&gt; Array
              (
                  [id] =&gt; 3
                  [name] =&gt; Others Works
                  [readable] =&gt; 1
                  [status] =&gt; active
              )
      );
  </code></pre>
  
  <p>which i need to compare.</p>
  
  <p>if <code>$array2['id']</code> is not in <code>$array1["activity"]</code>(i.e"activity_id") add array <code>['activity_id'=&gt;$array2['id'],'cnt'=&gt;0]</code> to  <code>$array1['activity']</code>.</p>
  
  <p>My result must be like</p>
  
  <pre><code>$result = Array
      (
          [0] =&gt; Array
              (
                  [hour] =&gt; 10
                  [activity] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [activity_id] =&gt; 1
                                  [cnt] =&gt; 2
                              )
                          [1] =&gt; Array
                              (
                                  [activity_id] =&gt; 2
                                  [cnt] =&gt; 1
                              )
                          [2] =&gt; Array
                              (
                                  [activity_id] =&gt; 3
                                  [cnt] =&gt; 0
                              )
                      )
              )
          [1] =&gt; Array
              (
                  [hour] =&gt; 11
                  [activity] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [activity_id] =&gt; 1
                                  [cnt] =&gt; 0
                              )
                          [1] =&gt; Array
                              (
                                  [activity_id] =&gt; 2
                                  [cnt] =&gt; 0
                              )
                          [2] =&gt; Array
                              (
                                  [activity_id] =&gt; 3
                                  [cnt] =&gt; 0
                              )
                      )
              )
          [2] =&gt; Array
              (
                  [hour] =&gt; 12
                  [percentage] =&gt; 0
                  [activity] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [activity_id] =&gt; 1
                                  [cnt] =&gt; 0
                              )
                          [1] =&gt; Array
                              (
                                  [activity_id] =&gt; 2
                                  [cnt] =&gt; 5
                              )
                          [2] =&gt; Array
                              (
                                  [activity_id] =&gt; 3
                                  [cnt] =&gt; 2
                              )
                      )
              )
      );
  </code></pre>
  
  <p>What i have tried is</p>
  
  <pre><code>$finalArray = array();
  foreach($array1 as $arr1) {
      foreach($array2 as $arr2) {
          if(!in_array($arr2['id'], $arr1['activity'])) {
              $array = ['activity_id'=&gt;$arr2['id'], 'cnt'=&gt;0];   
          }
          array_push($arr1['activity'], $array);
          unset($array);
      }
      array_push($finalArray, $result);
  }
  print_r($finalArray);
  </code></pre>
  
  <p><code>in_array()</code> function is not working as I excepted or I am trying to do it in the wrong way. Can someone helps me with this?</p>