Let me start off by saying that I am fairly new to php. I am trying to create a multidimensional array but running into a weird result when I look at the result. I have a feeling that the syntax I am using is not correct but cannot verify that anywhere online. So I am posing the question here.
Here is the gist of what I am trying to do:
// Given: $row["foo"] == "Hello" && $row["bar"] == 1
while($row = mysqli_fetch_array($query_result, MYSQLI_ASSOC)){
$multiArray[$i] = $row["foo"];
$multiArray[$i]["lorem"] = $row["bar"];
$i++;
}
When I go to print $multiArray[$i] I get: 1ello.
As I said I believe that the error lies in my syntax of how I am assigning this multidimensional array. Can someone please help me find a similar method to (what I can only guess) php madness above?
Thank you in advance!
You can’t combine data types in a same array value.
$multiArray[$i]only can have a value type, ( string, integer, or array), but in your code, you want an array and a string at the same time !A possible solution is ( but depends of your logic ) :