Lucky Lucky - 4 months ago 8
jQuery Question

Convert array to associative

I have following array using

print_r($data);


in php results to

$data=Array(
[0] => stdClass Object
(
[name] => location
[value] =>lko
)

[1] => stdClass Object
(
[name] => street_number
[value] => 425
)
)


Now I want to achieve the following format array ,How can i achieve followin using best complexity feasible

Array(
[location]=>lko
[street_number]=>425)


I want the perfect complexity feasible solution,

Answer

You can try the following

 foreach ($data as $val) {

    $ar[$val['name']]=$val['value'];
}
print_r($ar);

This will convert your array into the format you needed

Comments