How to remove array index from json object while convert array to jsonobject php? [closed]

First of all, I need to change your code to this to even get the result you’re talking about:

$arr = array('id' => $_POST['id'], 'name' => $_POST['name'], 'model' => $_POST['model'], 'color' => $_POST['color']);

$result = json_encode(array('success' => 1, 'message' => "Updated Successfully", $arr));

echo $result;

The problem you are facing with the key “0” is that you cannot have a value in JSON without a key (as other have stated in the comments). Notice that you set the key success and message, but you don’t set a key for $arr.

I think you should add a key data or something similar to it like this:

$arr = array('id' => $_POST['id'], 'name' => $_POST['name'], 'model' => $_POST['model'], 'color' => $_POST['color']);

$result = json_encode(array('success' => 1, 'message' => "Updated Successfully", 'data' => $arr));

echo $result;

Browse More Popular Posts

Leave a Comment