0

I know this question is being asked a lot, but I could not find any case similar to mine.

So I have this array printed out of a JSON response:

Array
(
    [contents] => {
    "type": "XXXXXXXXXXXXXXX",
    "previous": "XXXXXXXXXXXXXXX",
    "destination": "XXXXXXXXXXXXXXX",
    "balance": "XXXXXXXXXXXXXXX",
    "work": "XXXXXXXXXXXXXXX",
    "signature": "XXXXXXXXXXXXXXX"
}

)

I need to access the "destination" value, but keep getting an "invalid offset" error. How do I reach it? Thanks so much in advance!

3
  • What did you try? Is that the whole response? It's way better if you show us your efforts, that way we can help you figure it out why it went wrong, so you can learn how to fix it Commented Mar 10, 2018 at 18:44
  • 1
    where you need to access these values? backend or frontend? Commented Mar 10, 2018 at 18:45
  • is it multidimensional array { i never see this symbol [{] in multidimention array Commented Mar 10, 2018 at 18:52

1 Answer 1

4

You have given above array with key contents with some json value. First you have to convert that json into array. Check below, it might be help you:

<?php
$array = array(
    'contents' => '{
    "type": "XXXXXXXXXXXXXXX",
    "previous": "XXXXXXXXXXXXXXX",
    "destination": "XXXXXXXXXXXXXXX",
    "balance": "XXXXXXXXXXXXXXX",
    "work": "XXXXXXXXXXXXXXX",
    "signature": "XXXXXXXXXXXXXXX"
}'
);  

$content = json_decode($array['contents'],true);

echo $content['destination'];
Sign up to request clarification or add additional context in comments.

Comments

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.