why doesnt this array work? What do I do wrong? The result of my foreach loop is always either empty or just some weird numbers and signs. So what is wrong with my foreach loop?
$array = array();
while($row = mysqli_fetch_array($result)) {
if(!empty($row["some"])) {
$array["some"] = $row["some"];
$array["some2"] = $row["some2"];
}
}
foreach($array as $property=>$value) {
echo '<p>'.$value["some"].' - '.$value["some2"].'</p>'; }
$array["some"]and$array["some2"]are specific array elements. You are overwriting them every iteration of your while loop.Not sure what you’re trying to actually accomplish but I think possibly this is what you want:
or
or similar…kinda depends on what you’re ultimately trying to accomplish…