techker Posted March 24, 2020 Share Posted March 24, 2020 Hey guys i need to echo this: Quote { "error":false, "result":[{ "apk_sign":"0F:19:F7:2D:F0:40:2C:FE:25R:C1:EB:80:0FF:FC:92:DA:4F:BE:2F:9F", "portal_url":" http://changeme.net:80, http://changeme2.net:80, http://changeme3.net:80 "}] } Up to know i tried lots of combos but can seem to get the Array correctly? Quote $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 : Quote { "error":false, "result":{ "apk_sign":"0F:19:F7:2D:F0:40:2C:FE:25:C1:EB:80:0F:FC:92:DA:46:BE:23:9D", "portal_url":[ "http:\\\/\\\/changeme.net:80,http:\\\/\\\/changeme.net:80,http:\\\/\\\/changeme.net:80" ]} } but the [ needs to be at results.... Thx for the help Quote Link to comment https://forums.phpfreaks.com/topic/310366-echo-nested-arrays/ Share on other sites More sharing options...
ginerjm Posted March 24, 2020 Share Posted March 24, 2020 (edited) The answer is to use a recursive function. Run this: $array1 = array( 'key'=>'value', 'key2'=>'value2', 'key3'=>'value3', 'arr2'=>array( 'subkey'=>'subvalue', 'subkey2'=>'subvalue2' ), 'key4'=>'value4', 'arr3'=>array( 'subkey3'=>'subvalue3', 'subkey4'=>'subvalue4' ), 'lastkey'=>'lastvalue' ); DumpArray($array1); //*************************** function DumpArray($ar) { foreach($ar as $k=>$v) { if (is_array($v)) { echo "Array $k - "; DumpArray($v); } else echo "$k - $v<br>"; } echo "End array<br>"; return; } exit(); 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 March 24, 2020 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/310366-echo-nested-arrays/#findComment-1575738 Share on other sites More sharing options...
requinix Posted March 29, 2020 Share Posted March 29, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310366-echo-nested-arrays/#findComment-1576018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.