php - What is the problem with this foreach loop? -


why doesnt array work? do wrong? result of foreach loop either empty or weird numbers , signs. wrong foreach loop?

$array = array();  while($row = mysqli_fetch_array($result)) {     if(!empty($row["some"])) {         $array["some"] = $row["some"];         $array["some2"] = $row["some2"];     }  } foreach($array $property=>$value) { echo '<p>'.$value["some"].' - '.$value["some2"].'</p>'; } 

$array["some"] , $array["some2"] specific array elements. overwriting them every iteration of while loop.

not sure you're trying accomplish think possibly want:

$array = array();  while($row = mysqli_fetch_array($result)) {     if(!empty($row["some"])) {         $array["some"][] = $row["some"];         $array["some2"][] = $row["some2"];     }  } foreach($array["some"] $property=>$value) {   echo '<p>'.$value.' - '.$array["some2"][$property].'</p>';  } 

or

$array = array();  while($row = mysqli_fetch_array($result)) {     if(!empty($row["some"])) {         $array[] = array('some' => $row["some"],                          'some2' => $row["some2"]);     }  } foreach($array $property=>$value) {   echo '<p>'.$value['some'].' - '.$value['some2'].'</p>';  } 

or similar...kinda depends on you're trying accomplish...


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -