Paul Francis Paul Francis - 2 years ago 130
JSON Question

Removing array values without losing quotes

My Array :

echo json_encode($val);

Output :

Using unset to remove 'b' from location '1' :


Expecting Output as :

Is there any solution ? to get rid of keys and curl brackets and get output as expected!

Answer Source

You need to reset array keys. Check this:


echo json_encode($val);


echo json_encode($val); //outputs {"0":"a","2":"c"}

$val = array_values($val); //reset array keys
echo json_encode($val); //outputs ["a","c"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download