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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -