Jump to content

Echo nested arrays?


Recommended Posts

Hey guys i need to echo this:



Up to know i tried lots of combos but can seem to get the Array correctly?


$named_array3 = array(
         "error" => false,
         "result" => array(
            "apk_sign" => "0F:19:F7:2D:F0:40:2C:FE:25d:C1D:EB:80:0F:FCD:92:DA:46:BEF:23D:9DD",
            "portal_url" => "http:\/\/changeme.net:80,http:\/\/changeme.net:80,http:\/\/changeme.net:80")

it echos




   "result":{      "apk_sign":"0F:19:F7:2D:F0:40:2C:FE:25:C1:EB:80:0F:FC:92:DA:46:BE:23:9D",





but the [ needs to be at results....


Thx for the help

Link to comment
Share on other sites

The answer is to use a recursive function.  Run this:

$array1 = array(
function DumpArray($ar)
    foreach($ar as $k=>$v)
        if (is_array($v))
            echo "Array $k - ";
            echo "$k - $v<br>";
    echo "End array<br>";

You can add code to make the presentation neater if you want but at least this shows you how to process the nested arrays.


Edited by ginerjm
Link to comment
Share on other sites

array() can be used to create something that looks like an object (with keys) and something that looks like a list of things (no keys).

The result part has two opening symbols: [ and a {. The first one is a list, the second is an object.
Two symbols, two array()s. One inside the other.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.