php - How To Produce Multidimensional Array From While Loop? -


i have function :

function userkids(mysqli $con, $parent) {     $stmt = $con->prepare('select kidsname, kidsage, kidsgender kids parent = ?');     $stmt->bind_param('s', $username);     $stmt->execute();      $kid = null;     $kids = array();     $stmt->bind_result($kid, $kidsage, $kidsgender);     while($stmt->fetch()) {         $kids[] = $kid;     }     return $kids; } 

currently while loop produce array :

array ( [0] => john [1] => jane ) 

now, how produce multidimensional array can age , gender well, :

array ( [john] => array   (   [0] => 3   [1] => male   ) [jane] => array   (   [0] => 2   [1] => female   ) ) 

i recommend use associative array second dimension well. so:

$kids[$kid] = array('age' => $kidsage, 'gender' => $kidsgender); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -