Choosing the right method to use
suppose you have this array:
$player_quest_status = array("quest1" => 100,
"quest2" => 90,
"quest3" => 50);
you can have 2 options on storing these array into the database.
using PHP json_encode():
$player_quest_status_json = json_encode($player_quest_status); //then you can store $player_quest_status_json variable using INSERT.UPDATE
statements //array when encoded: {"quest1":100,"quest2":100,"quest3":100}
use json_decode to convert it back to array after retrieving the value from the database.
using PHP serialize():
$player_quest_status_json = serialize($player_quest_status); //array when encoded: a:3{s:6:"quest1";i:100;s:6:"quest2";i:100;s:6:"quest3";i:100;}
for more information which function you would like to use:
Preferred method to store PHP arrays (json_encode vs serialize)
though i still recommend json as it is more scalable.
Structuring your Arrays
$player_quest_status = array("player_id" => 1,
"level" => 1,
"quests" => array( 1/*quest_id*/ => array("percent_completed" => 100,
"quest_title" => "the first quest"),
2/*quest_id*/ => array("percent_completed" => 80,
"quest_title" => "the second quest"),
3/*quest_id*/ => array("percent_completed" => 50,
"quest_title" => "the 3rd quest")
)
);
$player_npc_status = array("npc" => array( 1 => array("name" => "lawrence",
"tasks" => array( 1 => array("task_title" => "title 1",
"is_completed" => 1),
2 => array("task_title" => "title 2",
"is_completed" => 1),
3 => array("task_title" => "title 3",
"is_completed" => 0))
),
2 => array("name" => "viscocent",
"tasks" => array( 1 => array("task_title" => "title 4",
"is_completed" => 1),
2 => array("task_title" => "title 5",
"is_completed" => 2),
3 => array("task_title" => "title 6",
"is_completed" => 0))
),
)
);