由于我之前的问题简化了,我正在尝试在 PHP 中学习 3D 数组,但是每节课我都变得难以理解。
我准备了带有空 3D(分层)数组的代码,但不知道如何:
- 用 MySQL 数据库中的数据填充它
- 像这样显示/引用它:
echo $result_value[x][y][z]
给出value
.
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];
}
}
}