0

Possible Duplicate:
Parsing JSON file with PHP

Can anyone suggest an elegant way to change an array of the form below to an array containing only the primary keys, using php?

[{
    "PrimaryKey": "489",
    "name": "Ted"
}, {
    "PrimaryKey": "488",
    "name": "Bill"
}, {
    "PrimaryKey": "487",
    "singleFbId": "Joe"
}]
Community
  • 1
  • 1
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
  • Looks like JSON. How about a json parser? Or you probably mean "traversing". Arrays are traversed in PHP using `foreach`. – mario Jan 23 '13 at 21:32

1 Answers1

0
<?php
$data = '[{
    "PrimaryKey": "489",
    "name": "Ted"
}, {
    "PrimaryKey": "488",
    "name": "Bill"
}, {
    "PrimaryKey": "487",
    "singleFbId": "Joe"
}]';

$array = json_decode($data, TRUE);

print_r($array);
Zemistr
  • 1,049
  • 7
  • 10