i am using php arrays in my project like below but i am confused should i use json encode or not what is good for my site here below i get the array returned by the function and loop through it and while using in my UI but i confused how JSON will do faster data access till whatever i googled i found JSON as only format for data transmission and it has nothing to do with the data access speed so should i stick to my current scenario.
function get_single_article($article_id)
{
$sql="select * from articles where article_id=".$article_id."";
$query=mysql_query($sql);
$data=mysql_fetch_row($query);
return $data;
}
JSON is meant for transmitting data and objects from a server to a client in a language-agnostic fashion. If you’re writing just a pure PHP function to be included and called within a script, there’s no reason to JSON encode your data. It’s just extra overhead to encode and decode it. The only reason you should JSON encode is if you’re passing the information back from an AJAX call.