Reputation: 14835
$mystring = '{
"display_name": "Silverware",
"user": "joesmith",
"id": 27,
"field_name": "Age",
"sort_order": 1,
"required": 0,
"view_type": "text"
}';
I'd like a PHP array with all of the keys from the code above. Whats the most efficient way?
Upvotes: 6
Views: 12914
Reputation: 92854
get all of the keys in this JSON with PHP
Short solution using json_decode
and array_keys
functions:
$keys = array_keys(json_decode($mystring, true));
Upvotes: 15