php - Convert array of objects with keys to keyed array -


i have array of objects defined {'preference name',value}. example

$preferences[] = {'abc',123}; $preferences[] = {'def',456}; 

i'd access them this:

$pref = $preferences['abc']; 

of course, know assign them keyed array begin with, i'm getting values via json, , json_decode creates array of objects. example json leads situation above be:

{'abc':123,'def':456} 

obviously it's trivial covert these using loop, wondered if there better one-liner might job?

if decode json associative arrays , properties unique, merge sub arrays:

$preferences = json_decode($json, true); $preferences = call_user_func_array('array_merge', $preferences); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -