Reputation: 2148
I have a text file which displays all the records in datatables correctly but I want to display only the records with "ram". For example:
{ "aaData": [
["ram","india"],
["siva","india"],
["mani","india"],
["ram","india"],
["ram","india"]
] }
I am using PHP and Symfony1.3. Please help me.
Upvotes: 1
Views: 274
Reputation: 4323
try this :
$json_str = '{ "aaData": [
["ram","india"],
["siva","india"],
["mani","india"],
["ram","india"],
["ram","india"]
] }
';
$array = json_decode($json_str, true);
$entries_with_ram = array();
foreach($array['aaData'] as $entry)
if($entry[0] == "ram")
$entries_with_ram[] = $entry;
print_r($entries_with_ram);
Upvotes: 1
Reputation: 382806
You could try this:
$array = json_decode($json_str, true); // convert json to array
print_r($array['ram']); // display items with ram key
Upvotes: 1