As my previous questions simplify I am trying to learn 3D arrays in PHP but each lesson is getting difficult to understand by me.
I have prepared code with empty 3D (layered) array but don't know how to:
- populate it with data from MySQL database
- display it/reffer to it like:
echo $result_value[x][y][z]givesvalue
.
include_once 'connect.php';
$player_id = '6';
$result_value = array();
$pullMapInfo = "SELECT x, y, z, value FROM mapinfo WHERE id='{$player_id}'";
$pullMapInfo2 = mysql_query($pullMapInfo) or die(mysql_error());
while ( $pullMapInfo3 = mysql_fetch_assoc($pullMapInfo2) ) {
$result_value = array(
array(
array('', '', ''),
array('', '', ''),
array('', '', ''),
),
array(
array('', '', ''),
array('', '', ''),
array('', '', ''),
),
array(
array('', '', ''),
array('', '', ''),
array('', '', ''),
)
);
}
for($z = 1; $z <= 3; $z++){
for($x = 1; $x <= 16; $x++){
for($y = 1; $y <= 16; $y++){
# echo database row's divided among layers (z parameter) for ex.: 1,1,1 = red (X,Y,Z = color value) - 1 width & 1 height on 1st layer contains red value
# to get access to it like this: $result_value[x][y][z] => [value];
}
}
}
mysql_fetch_objectfor example. It is also considered nice to answer people willing to help you when they request clarification.