0

So I got this array:

$list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml');

if($list) {
    $data = array('firmware' => $list->region->system_pup[0]['label']);

    header('Content-Type: application/json');

    echo json_encode($data);
}

And it outputs this:

{"firmware":{"0":"5.01"}}

But there's also a zero there. How do I remove it from the array so it's like this:

{"firmware":"5.01"}

1 Answer 1

1

This is a SimpleXMLElement result which you need to convert to a string if you want that data:

$data = array('firmware' => (string) $list->region->system_pup[0]['label']);

In JSON form it looks like an associative array, which it isn't, so the [0] trick which normally works to navigate to it won't.

Sign up to request clarification or add additional context in comments.

2 Comments

I've updated the answer. Note that using var_dump showed what this result actually was, so if you're ever stumped, try that first.
@FirstOne I think the {'0'=>...} stuff is just an ugly artifact of how SimpleXMLElement is implemented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.