mysql - Merge multiple array to single array -


i have piece of code wish single array contains value.

$sql = "select * interest interest='".$interest."' , userid!='".$myuserid."'"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0)      {         while($row = mysqli_fetch_assoc($result))              {                 $userid = $row["userid"];                  if($searchtype == 'both')                     {                         $sql2 = "select * register id='".$userid."' ,  discover = 'on' , id!='".$myuserid."'";                         $result2 = mysqli_query($conn, $sql2);                         if (mysqli_num_rows($result2) > 0)                              {                                 while($row2 = mysqli_fetch_assoc($result2))                                      {                                         echo "<pre>";                                         print_r($row2);                                         echo "</pre>";                                     }                             }                            }             }     } 

the o/p getting this

array (     [id] => 1     [email] => a1     [username] =>b1      [password] => c1     [gender] => c1 )  array (     [id] => 2     [email] => a2     [username] => b2     [password] => c2     [gender] => d2 ) array (     [id] => 3     [email] => a3     [username] => b3     [password] => c3     [gender] => d3 ) 

but wish data in single array this

array (     [0] => array         (              [id] => 1              [email] => a1              [username] =>b1               [password] => c1              [gender] => c1         )      [1] => array         (             [id] => 2             [email] => a2             [username] => b2             [password] => c2             [gender] => d2         )      [2] => array         (             [id] => 3             [email] => a3             [username] => b3             [password] => c3             [gender] => d3         ) } 

can tell how can

take 1 array variable before while loop started $user_data = array(); , in inner loop have set $user_data[] = $row2;

if (mysqli_num_rows($result) > 0) {     $user_data = array();     while($row = mysqli_fetch_assoc($result)) {             $userid = $row["userid"];             if($searchtype == 'both') {                     $sql2 = "select * register id='".$userid."' ,  discover = 'on' , id!='".$myuserid."'";                     $result2 = mysqli_query($conn, $sql2);                     if (mysqli_num_rows($result2) > 0) {                             while($row2 = mysqli_fetch_assoc($result2)) {                                     $user_data[] = $row2;                                 }                         }                        }         }    print_r($user_data);   //print here user_data outside loop. } 

Comments