PHP Illegal Offset Type when creating array -
i trying make fake data in form of array in php , keep getting illegal offset type error when running line, explain why?
i looked reasons illegal offset errors , doesn't seem accessing data via offset, attempting create array, , no see spot using object association array.
$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") ) ) );
you have remove '[' , ']'. here corrected code
<?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") ) ) ); ?> <pre><?php print_r($fake_data); ?></pre>
Comments
Post a Comment