I am json encoding result from a mysql query in a php file. My php script is as follows:
while ($row = mysql_fetch_array($result)) {
   $to_encode[] = $row;
}
echo json_encode($to_encode);
My Output
[
  {
    "0": "Variables",
    "topic_name": "Variables",
    "1": "pyt1.1",
    "rdf_id": "pyt1.1",
    "2": "Hello World",
    "ex_name": "Hello World",
    "3": "1",
    "line_number": "1",
    "4": "print (\"Hello World!\")",
    "code": "print (\"Hello World!\")",
    "5": "Some Comment",
    "comment": "Some Comment"
  }
]
Here, as you can see every alternate lines are redundant. I do not need lines 1,3,5...and so on.
Desired Output
[
  {
    "topic_name": "Variables",
    "rdf_id": "pyt1.1",
    "ex_name": "Hello World",
    "line_number": "1",
    "code": "print (\"Hello World!\")",
    "comment": "Some Comment"
  }
]
How to change the php script to achieve the desired output?
 
     
     
    