I probably am asking this(1. as a newbie & 2. as a result of my own curiosity in what really happens). And my question is based on if data is pulled from DB, which is the recommended way and why? I have seen code from other developers that access elements of an array using the first scenario but I haven't seen the json_encode
or json_decode
$x = array("fname" => "John", "lname" => "Doe", "age" => 28);
first scenario, to access an element say fname
$x = json_encode($x); // a
$x = json_decode($x); // b
echo $x->fname; // (c) outputs John
Scenario 2
// comment a, b and c above
// to access the same element fname
echo $x['fname']; // outputs John