Patrick Helms Patrick Helms - 1 year ago 95
JSON Question

json_encode dropping array_values key?

I am working in PHP and have an issue with

. The process wipes the inital "key" that was set by the "array_values" command as shown below.

array(1) {
[0]=> array(5) {
["ID"]=> string(4) "2679" [
"PackageName"]=> "Update for Windows 8.1 for x64-based Systems (KB2965065)"
["Description"]=> string(262) "Install this update to resolve issues in Windows."
["KB"]=> string(7) "2965065"
["Repo"]=> string(21) "Windows Update Server"

$packages = array_values($this->control->fetchPackageTables($this->input->get("platform")));

"PackageName":"Update for Windows 8.1 for x64-based Systems (KB2965065)",
"Description":"Install this update to resolve issues in Windows.",
"Repo":"Windows Update Server"

I have tried looping with a foreach through the array and setting a number but it still gets dropped. Any ideas?


Answer Source

JSON does not support associative arrays.

Arrays in JSON / Javascript consist only of numbered indexes. Associative arrays will be converted to objects/properties.

There is nothing getting dropped. [ ] indicates an array. { } indicates an object. You have one object in the array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download