0

When I use <pre>to display my variable echo $value_detail_final;
it displays a proper file like this

    {
        "companies": [
        {
        "id": "4127303000000527195",
        "company_name": "235 St Georges Landowning Trust & Australian City Properties Pty Ltd"
        },
        {
        "id": "4127303000004495043",
        "company_name": "Bourke Junction No 1 Pty Ltd"
        },
        {
        "id": "4127303000000527189",
        "company_name": "Brookfield Commercial Operations Pty Ltd"
        } 
       ]
    }

But when I use something like this $value_detail_final[0] it displays {
if $value_detail_final[1] its ", its like displaying each character on my variable .

even foreach doesnt work, by the way this is from json file and I use json_decode file.

How can I able to put each of the id and company_name into a variable so I can use them ?

This is how I decode my json file based on the given sturcture

$jsondata = file_get_contents("response.json");

$array = json_decode($jsondata,true);
echo "<pre>";
foreach ($array as $key => $value) {

    // echo "Key:".$key."<br>";
    if($key=='details')
    {
        foreach ($value as $key_detail => $detail)
        {

            if($key_detail=='userMessage')
            {
                foreach ($detail as $key_detail_final => $value_detail_final)
                {
                    print_r($value_detail_final);
                }
            }
        }
    }
}
7
  • Then it is double encoded or something [0] is the first character of a string and that's what you get {. Show what you get and how you decode it and what is the result. Commented Nov 24, 2020 at 1:31
  • @AbraCadaver I added my decode function Commented Nov 24, 2020 at 1:35
  • @catcon so I will twice json_decode() ? Commented Nov 24, 2020 at 1:37
  • @all I already added my json_decode function Commented Nov 24, 2020 at 1:40
  • 2
    This makes no sense, there is no userMessage and the code doesn't match with what you say you want to do. Commented Nov 24, 2020 at 1:45

0

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.