我想在PHP中以數組的形式製作一些假數據,並在運行此行時不斷獲得非法偏移類型錯誤,任何人都可以幫助解釋原因嗎?PHP創建陣列時非法偏移類型
我查找了非法偏移錯誤的原因,它似乎並不像我通過偏移量訪問任何數據,我嘗試創建一個數組,並且沒有在哪裏可以看到我正在使用對象的位置作爲數組的關聯。
$fake_data = array(
["game_id"] => "1",
["turn_number"] => "1",
["host_user"] => array(
["units"] => array(
array("row"=> "1", "col" => "1", "hp" => "100", "armor" => "100", "is_dead" => "0", "direction_facing" => "1", "name" => "AssaultAlpha"),
array("row"=> "1", "col" => "2", "hp" => "100", "armor" => "100", "is_dead" => "0", "direction_facing" => "1", "name" => "JuggernautAlpha"),
array("row"=> "1", "col" => "3", "hp" => "100", "armor" => "100", "is_dead" => "0", "direction_facing" => "1", "name" => "MedicAlpha")
),
["hit_indicators"] => array(
array("row"=> "1", "col" => "3", "direction" => "1"),
array("row"=> "1", "col" => "2", "direction" => "1")
)
),
["client_user"] => array(
["units"] => array(
array("row"=> "5", "col" => "1", "hp" => "100", "armor" => "100", "is_dead" => "0", "direction_facing" => "1", "name" => "AssaultAlpha"),
array("row"=> "6", "col" => "2", "hp" => "100", "armor" => "100", "is_dead" => "0", "direction_facing" => "1", "name" => "JuggernautAlpha"),
array("row"=> "7", "col" => "3", "hp" => "100", "armor" => "100", "is_dead" => "0", "direction_facing" => "1", "name" => "MedicAlpha")
),
["hit_indicators"] => array(
array("row"=> "5", "col" => "3", "direction" => "1"),
array("row"=> "6", "col" => "2", "direction" => "1")
)
)
);
什麼是**精確**錯誤信息,你會得到什麼? – Rizier123
閱讀[數組文檔](https://php.net/manual/en/language.types.array.php)。您正在使用不正確的語法。 –