Enjin API (JSON) to PHP part 2 - php
I'm trying to figure out how to get the data from http://www.natomilcorp.com/api/get-tags
But I doesn't work the way it was working with http://www.natomilcorp.com/api/get-users
<?php
$content = file_get_contents('http://natomilcorp.com/api/get-tags');
$array = json_decode($content, TRUE);
foreach ($array as $key => $value) {
}
?>
Should return something like : Major
There's the id for the rank + id of each user with that rank. How could I do that?
Data I'm trying to get.
Array ( [tags] => Array ( [766910] => Array ( [name] => Major [visible] => 2 [users] => Array ( [0] => 200159 ) ) [766912] => Array ( [name] => Captain [visible] => 2 [users] => Array ( [0] => 2261591 ) ) [766913] => Array ( [name] => 1st Lieutenant [visible] => 2 [users] => Array ( [0] => 9054053 ) ) [766914] => Array ( [name] => 2nd Lieutenant [visible] => 2 [users] => Array ( [0] => 8987889 ) ) [773490] => Array ( [name] => Sergeant First Class [visible] => 2 [users] => Array ( [0] => 7725577 ) ) [773492] => Array ( [name] => Sergeant [visible] => 1 [users] => Array ( [0] => 1060956 [1] => 7302252 [2] => 8757300 [3] => 8863799 [4] => 8965561 [5] => 9261041 ) ) [773493] => Array ( [name] => Corporal [visible] => 2 [users] => Array ( [0] => 3021405 [1] => 7007387 [2] => 9139763 [3] => 9213371 ) ) [773494] => Array ( [name] => Private First Class [visible] => 2 [users] => Array ( [0] => 2200849 [1] => 3641961 [2] => 9178511 [3] => 9261322 [4] => 9323849 [5] => 9389371 [6] => 9430088 ) ) [773495] => Array ( [name] => Private [visible] => 2 [users] => Array ( [0] => 114357 [1] => 261041 [2] => 304466 [3] => 549312 [4] => 1118346 [5] => 1710685 [6] => 2141867 [7] => 3211667 [8] => 3310027 [9] => 3553805 [10] => 4528862 [11] => 7379434 [12] => 8403949 [13] => 8428123 [14] => 8650774 [15] => 8910960 [16] => 9010718 [17] => 9141940 [18] => 9223268 [19] => 9276028 [20] => 9308336 [21] => 9324049 [22] => 9343007 [23] => 9379991 [24] => 9388650 [25] => 9388744 [26] => 9501913 ) ) [773499] => Array ( [name] => Recruit [visible] => 2 [users] => Array ( [0] => 89975 [1] => 205838 [2] => 384035 [3] => 1607344 [4] => 3131066 [5] => 6461552 [6] => 7126984 [7] => 7233456 [8] => 8594187 [9] => 9210020 [10] => 9319294 [11] => 9324467 [12] => 9368201 [13] => 9401020 [14] => 9401208 [15] => 9411271 [16] => 9412511 [17] => 9442152 [18] => 9472151 [19] => 9481048 [20] => 9507716 [21] => 9519155 [22] => 9519665 [23] => 9524202 [24] => 9524528 [25] => 9527256 [26] => 9528148 [27] => 9528464 [28] => 9532974 [29] => 9532993 ) ) [794713] => Array ( [name] => NMC Member [visible] => 0 [users] => Array ( [0] => 89975 [1] => 114357 [2] => 200159 [3] => 205838 [4] => 304466 [5] => 384035 [6] => 549312 [7] => 857679 [8] => 870831 [9] => 1060956 [10] => 1118346 [11] => 1607344 [12] => 1710685 [13] => 2141867 [14] => 2200849 [15] => 2261591 [16] => 3021405 [17] => 3131066 [18] => 3211667 [19] => 3310027 [20] => 3553805 [21] => 3641961 [22] => 4528862 [23] => 5888412 [24] => 6461552 [25] => 7007387 [26] => 7126984 [27] => 7233456 [28] => 7302252 [29] => 7379434 [30] => 7725577 [31] => 8403949 [32] => 8428123 [33] => 8594187 [34] => 8650774 [35] => 8757300 [36] => 8863799 [37] => 8910960 [38] => 8965561 [39] => 8987889 [40] => 9010718 [41] => 9017629 [42] => 9054053 [43] => 9139763 [44] => 9141940 [45] => 9178511 [46] => 9210020 [47] => 9213371 [48] => 9223268 [49] => 9261041 [50] => 9261322 [51] => 9276028 [52] => 9289688 [53] => 9308336 [54] => 9319294 [55] => 9323849 [56] => 9324049 [57] => 9324467 [58] => 9343007 [59] => 9361657 [60] => 9368201 [61] => 9379991 [62] => 9388650 [63] => 9388744 [64] => 9389371 [65] => 9401020 [66] => 9401208 [67] => 9411271 [68] => 9412511 [69] => 9430088 [70] => 9442152 [71] => 9472151 [72] => 9481048 [73] => 9501913 [74] => 9507716 [75] => 9519155 [76] => 9519665 [77] => 9524202 [78] => 9524528 [79] => 9527256 [80] => 9528148 [81] => 9528464 [82] => 9532974 [83] => 9532993 ) ) [905780] => Array ( [name] => Reserve / Inactive [visible] => 2 [users] => Array ( [0] => 1116431 [1] => 1146450 [2] => 1327008 [3] => 3488556 [4] => 4057254 [5] => 4109011 [6] => 4442271 [7] => 5075797 [8] => 6348486 [9] => 6727549 [10] => 7482138 [11] => 7669434 [12] => 7810956 [13] => 7813040 [14] => 7845349 [15] => 7873320 [16] => 8163829 [17] => 8610931 [18] => 8720229 [19] => 8758932 [20] => 8944586 [21] => 8988410 [22] => 9009221 [23] => 9016644 [24] => 9143121 ) ) [916781] => Array ( [name] => High Command [visible] => 2 [users] => Array ( [0] => 192868 ) ) [950454] => Array ( [name] => (AF) 2nd Lieutenant [visible] => 2 [users] => Array ( [0] => 870831 [1] => 5888412 [2] => 9017629 [3] => 9289688 [4] => 9361657 ) ) [950472] => Array ( [name] => (AF) 1st Lieutenant [visible] => 2 [users] => Array ( [0] => 857679 ) ) [964515] => Array ( [name] => 8 Week Service Ribbon 1A [visible] => 2 [users] => Array ( [0] => 857679 [1] => 3021405 [2] => 8428123 ) ) [964541] => Array ( [name] => 8 Week Service Ribbon 2A [visible] => 2 [users] => Array ( [0] => 7725577 ) ) [964552] => Array ( [name] => 8 Week Service Ribbon 4A [visible] => 2 [users] => Array ( [0] => 200159 ) ) [964580] => Array ( [name] => Altis War Service Ribbon [visible] => 2 [users] => Array ( [0] => 200159 [1] => 857679 [2] => 870831 [3] => 1060956 [4] => 2261591 [5] => 5888412 [6] => 7302252 [7] => 7725577 [8] => 8757300 [9] => 8863799 [10] => 8965561 [11] => 9054053 ) ) [964632] => Array ( [name] => Commanding Officers Commendation [visible] => 2 [users] => Array ( [0] => 2261591 [1] => 9054053 [2] => 9139763 [3] => 9261322 ) ) [964807] => Array ( [name] => Executive Officers Commendation [visible] => 2 [users] => Array ( [0] => 5888412 [1] => 8863799 [2] => 9017629 ) )
It should be
echo $array['tags'][$key]['name'];
You could see there is a tags key , so you need to add that too while accessing.
Working code..
<?php
$content = file_get_contents('http://natomilcorp.com/api/get-tags');
$array = json_decode($content, TRUE);
$key = "766910";
echo $array['tags'][$key]['name'];
Related
Php array saving values only till 62 indices
I am sending a big array of 130+ indices from ajax to php. But while going to php, if i print, it became a 2D array with indices 63, 63, 6 respectively. Below is snip Array ( [0] => Array ( [0] => 943900200 [1] => 1297017000 [2] => 1299436200 [3] => 1302114600 [4] => 1304879400 [5] => 1307385000 ................ [60] => 1452105000 [61] => 1454869800 [62] => 1457375400 ) [1] => Array ( [0] => 943900200 [1] => 1297017000 [2] => 1299436200 [3] => 1302114600 [4] => 1304879400 [5] => 1307385000 ...... [61] => 1454869800 [62] => 1457289000 ) [2] => Array ( [0] => 1440441000 [1] => 1443033000 [2] => 1445970600 [3] => 1445970600 [4] => 1447007400 [5] => 1448908200 ) ) But i want them in a single D array...[0]--[127] together. I tried to copy them using foreach aswell. It copies the first 63 indices and stops. Any one please help. Thanks
You must use foreach twice: INTPUT (example): Array ( [0] => Array ( [0] => 5031750 [1] => 3972258 [2] => 1673731 [3] => 721866 [4] => 4031885 [5] => 1454990 ) [1] => Array ( [0] => 1115002 [1] => 27608 [2] => 3531620 [3] => 4412066 [4] => 4032217 [5] => 2681734 ) [2] => Array ( [0] => 3360879 [1] => 5190034 [2] => 3452229 [3] => 5112636 [4] => 628357 [5] => 4299124 ) ) PHP Code: $output = array(); foreach($input as $key=>$sub){ foreach($sub as $k => $v){ $output[] = $v; } } print_r($output); Output: Array ( [0] => 5031750 [1] => 3972258 [2] => 1673731 [3] => 721866 [4] => 4031885 [5] => 1454990 [6] => 1115002 [7] => 27608 [8] => 3531620 [9] => 4412066 [10] => 4032217 [11] => 2681734 [12] => 3360879 [13] => 5190034 [14] => 3452229 [15] => 5112636 [16] => 628357 [17] => 4299124 )
Get common values from a single multidimensional array in php
I have a array called $array which is multidimensional array. It consits of keys like brandname, productsubcategory (Keys are not static they can be anything and even number of keys are not fixed). I want all the common values from the array Current array: $array = array ( [brandname] => Array ( [0] => Array ( [0] => sony_brandname [1] => touch screen_type [3] => 2.8_size [4] => gsm + gsm_sim_support [5] => 2_primary_camera [6] => 64 mb_internal_memory [7] => 32_expandable_memory [8] => 1200_standard_battery_type [9] => 3_size [10] => 1000_standard_battery_type [11] => touch and type_type ) ) [productsubcategory] => Array ( [1] => Array ( [0] => karbonn_brandname [1] => touch and type_type [2] => micromax_brandname [3] => 2.8_size [4] => gsm_sim_support [5] => 3.15_primary_camera [6] => 52 mb_internal_memory [7] => 8_expandable_memory [8] => 1000_standard_battery_type [9] => nokia_brandname [10] => symbian s40_os_clean [11] => 5_primary_camera [12] => 128 mb_ram [13] => 256 mb_internal_memory [14] => 32_expandable_memory [15] => 1110_standard_battery_type [16] => gsm + gsm_sim_support [17] => 2_primary_camera [18] => 32 mb_ram [19] => 10 mb_internal_memory [20] => no_expandable_memory [21] => 1020_standard_battery_type [22] => 680 mhz_processor [23] => 64 mb_ram [24] => 128 mb_internal_memory [25] => 860_standard_battery_type [26] => blackberry_brandname [27] => 2.45_size [28] => 1 ghz_processor ) ) ); Desired array : $array = array ( [0] => sony_brandname [1] => touch and type_type [2] => 2.8_size [8] => 1000_standard_battery_type [16] => gsm + gsm_sim_support [17] => 2_primary_camera )
Use array_intersect(): $result = array_intersect($array["brandname"][0], $array["productsubcategory"][1]); print_r($result);
PHP grabbing an array from another array
I have an array like so Array ( [0] => Array ( [64579] => Array ( [title] => title [description] => blah, blah, blah [image] => Array ( [original] => Array ( [src] => image1.jpg ) [reference] => Array ( [src] => image1_big.jpg ) [thumb] => Array ( [src] => image1_thumb.jpg ) ) What I am trying to grab is the src of reference image...I have tried the following foreach($images as $row => $value){ $gallery[] = $value['image']; } but it returns like so Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => [29] => [30] => [31] => [32] => [33] => [34] => [35] => [36] => [37] => [38] => [39] => [40] => [41] => [42] => [43] => [44] => [45] => [46] => [47] => [48] => ) What do I have to do to add the reference image src to my new gallery array?
What you have is a three dimensional array... you need to wrap this in another loop.. foreach($images as $imageGroupList) foreach($imageGroupList as $row => $value){ $gallery[] = $value['image']; } } of if your top level array only ever has a single element you can just iterate of it foreach($images[0] as $row => $value){ $gallery[] = $value['image']; }
How can I process this string so I end up with an array that just contains the full name & the associated jpg URL for each entity?
I have the following string which I need to extract the full name plus the URI/URL associated with it into an array for each one. It's not constructed like typical data, so I am unsure how to proceed. I thought explode at first, but there is "garbage" data in the beginning not needed, so I need a way to maybe cleanse the data first? But maybe there is an efficient way of doing this in one or two steps/stages so my code is efficient? After some research I am thinking mb_split() but I am very poor at constructing regex. Need some direction here... In my example below, you can see the data pattern that emerges after the initial "junk". The 3rd "row" for each grouping that forms is where the meat (aka data) that I seek is. The first string in that first grouping, in the 3rd row in the example is "Amanda Grider". This is the full name and its position in the returned data example I am looking for from each grouping. Further along that row is the URI/URL for the jpg image, which is the second piece of data I seek. Everything else as far as I am concerned is garbage and can get tossed. What is the fastest, most efficient way to process this chunk and get the values I seek into an array so i can use this in my work? (BTW, the following code I hand added return characters to make the data more easily understood. In reality, there are no return characters and it presents as one big string) [ [ "tsg.lac", [], [ [ [null,null,"100829745667958569941"], [], ["Amanda Grider",null,null,null,"4b3347c83f0a1","8nwbFHob02C8CmojHF","BoZrAHx801Rz8o3h8k",null,"https://lh3.googleusercontent.com/-zIK8ZN_ZDt8/AAAAAAAAAAI/AAAAAAAAAAA/fsiR92bLDlU/photo.jpg",null,1,"Marina del Rey, CA",null,null,null,0,null,[],null,null,null,""], [] ],[ [null,null,"115014076410206782853"], [], ["VWvortex",null,null,null,"4b13c6667b3c9","JKCGFo_CApJ","JKCGFo_CApJ",null,"//lh6.googleusercontent.com/-X_wSt8nwpOU/AAAAAAAAAAI/AAAAAAAAACQ/R_jcIPcegbM/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://WWW.VWVORTEX.COM",null,null,3],null,null,"World's largest Volkswagen enthusiast community and blog."], [] ],[ [null,null,"102608018926739248428"], [], ["Wale",null,null,null,"4b1ded89a3721","JmRxAk","JmRxAk",null,"//lh4.googleusercontent.com/-xyeyjc4Avow/AAAAAAAAAAI/AAAAAAAAABU/SY-9EKeDnhw/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.ralphfolarin.com/",null,null,6],null,null,""], [] ],[ [null,null,"114161985228080012446"], [], ["The Opus Rhythm Music Blog",null,null,null,"4b177a5207d09","IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB","IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB",null,"//lh5.googleusercontent.com/-4QRl1IgDCLU/AAAAAAAAAAI/AAAAAAAAABI/pVoxTQ7SH8Y/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.bacchusentertainment.com",null,null,6],null,null,"We are the team music blog of Bacchus Entertainment"], [] ],[ [null,null,"114645267718535118440"], [], ["Jalopnik",null,null,null,"4b12fccb6f809","DHRxFoK0Cng","DHRxFoK0Cng",null,"//lh6.googleusercontent.com/-_M1nn9mKyY8/AAAAAAAAAAI/AAAAAAAAABI/aXhkyN7cuuk/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://jalopnik.com/",null,null,3],null,null,"Jalopnik: Drive Free or Die"], [] ],[ [null,null,"105503202599719238167"], [], ["Audi USA",null,null,null,"4b14db7535e99","8owhCkGEHmR","8owhCkGEHmR",null,"//lh3.googleusercontent.com/-mHHyVhWfARE/AAAAAAAAAAI/AAAAAAAAAC4/Qn0lYbilT8M/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.audiusa.com","(800) 822-2834",null,3],null,null,"Progress is social media, and listening, and fans, and Google+. So here we are."], [] ],[ [null,null,"104108787932235341403"], [], ["Audi Sport",null,null,null,"4b23243c864b1","8owhCkGAGJC8IF","8owhCkGAGJC8IF",null,"//lh4.googleusercontent.com/-jGBNL9dbwYs/AAAAAAAAAAI/AAAAAAAAAUA/pgsAqvaX8XM/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.facebook.com/AudiSportPage",null,null,6],null,null,"Unofficial Audi Sport fan page, not affiliated with or endorsed by Audi AG."], [] ],[ [null,null,"106689856342933829975"], [], ["Volkswagen USA",null,null,null,"4b20ca9b7fa69","JJBxDohI8nBjFFGEHmR","JJBxDohI8nBjFFGEHmR",null,"//lh5.googleusercontent.com/-i3MO9CsymQ8/AAAAAAAAAAI/AAAAAAAAAB4/ddmTW3D8s20/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.vw.com","(800) 822-8987",null,3],null,null,"Take a look around, kick the tires, ask questions and get to know our community."], [] ],[ [null,null,"115425298803319911308"], [], ["Internal Frequency",null,null,null,"4b177b6d46119","Co4CAo_08no3BJZjGowjFHhM","Co4CAo_08no3BJZjGowjFHhM",null,"//lh4.googleusercontent.com/-lZeecuGL3Ig/AAAAAAAAAAI/AAAAAAAAABk/Afv5eGuBzUM/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.internalfrequency.com",null,null,6],null,null,"The 1st hand ups-and-downs of the CEO of an up-and-coming entertainment label in Southern California"], [] ],[ [null,null,"101358795463286919640"], [], ["Music Think Tank",null,null,null,"4b1947fea8251","EoxACmg3IIJrFIg3IHS0Dk","EoxACmg3IIJrFIg3IHS0Dk",null,"//lh4.googleusercontent.com/-B2KTfl4uNyE/AAAAAAAAAAI/AAAAAAAAACM/N955ZhPV08E/photo.jpg",null,1,null,null,null,null,0,null,[],[null,"http://www.musicthinktank.com",null,null,6],null,null,"Where the music industry speaks out loud. Create the Chaos."], [] ] ] ] ] UPDATE: So I stumbled on something and discovered the data is in fact valid JSON, does get decoded and passed back but still something odd and seems very complex (too complex for what I need). I use json_decode() to prase the data, which then is assigned to the variable $jsondata. When I added the following immediately after that: print_r ( print_r($jsondata)); I got this (I added return characters so it makes more sense and can be easily read): Array ( [0] => Array ( [0] => tsg.lac [1] => Array () [2] => Array ( [0] => Array ( [0] => Array ( [0] => [1] => [2] => 100829745667958569941 ) [1] => Array ( ) [2] => Array ( [0] => Amanda Grider [1] => [2] => [3] => [4] => 4b33843806e03 [5] => 8nwbFHob02C8CmojHF [6] => BoZrAHx801Rz8o3h8k [7] => [8] => https://lh3.googleusercontent.com/-zIK8ZN_ZDt8/AAAAAAAAAAI/AAAAAAAAAAA/fsiR92bLDlU/photo.jpg [9] => [10] => 1 [11] => Marina del Rey, CA [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => [19] => [20] => [21] => ) [3] => Array ( ) ) [1] => Array ( [0] => Array ( [0] => [1] => [2] => 115014076410206782853 ) [1] => Array ( ) [2] => Array ( [0] => VWvortex [1] => [2] => [3] => [4] => 4b13c6667b3c9 [5] => JKCGFo_CApJ [6] => JKCGFo_CApJ [7] => [8] => //lh6.googleusercontent.com/-X_wSt8nwpOU/AAAAAAAAAAI/AAAAAAAAACQ/R_jcIPcegbM/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://WWW.VWVORTEX.COM [2] => [3] => [4] => 3 ) [19] => [20] => [21] => World's largest Volkswagen enthusiast community and blog. ) [3] => Array ( ) ) [2] => Array ( [0] => Array ( [0] => [1] => [2] => 102608018926739248428 ) [1] => Array ( ) [2] => Array ( [0] => Wale [1] => [2] => [3] => [4] => 4b1ded89a3721 [5] => JmRxAk [6] => JmRxAk [7] => [8] => //lh4.googleusercontent.com/-xyeyjc4Avow/AAAAAAAAAAI/AAAAAAAAABU/SY-9EKeDnhw/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.ralphfolarin.com/ [2] => [3] => [4] => 6 ) [19] => [20] => [21] => ) [3] => Array ( ) ) [3] => Array ( [0] => Array ( [0] => [1] => [2] => 114161985228080012446 ) [1] => Array ( ) [2] => Array ( [0] => The Opus Rhythm Music Blog [1] => [2] => [3] => [4] => 4b177a5207d09 [5] => IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB [6] => IIJj03C4Iog3HIKMIIJz02xEHnRf01ZxFnB [7] => [8] => //lh5.googleusercontent.com/-4QRl1IgDCLU/AAAAAAAAAAI/AAAAAAAAABI/pVoxTQ7SH8Y/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.bacchusentertainment.com [2] => [3] => [4] => 6 ) [19] => [20] => [21] => We are the team music blog of Bacchus Entertainment ) [3] => Array ( ) ) [4] => Array ( [0] => Array ( [0] => [1] => [2] => 114645267718535118440 ) [1] => Array ( ) [2] => Array ( [0] => Jalopnik [1] => [2] => [3] => [4] => 4b12fccb6f809 [5] => DHRxFoK0Cng [6] => DHRxFoK0Cng [7] => [8] => //lh6.googleusercontent.com/-_M1nn9mKyY8/AAAAAAAAAAI/AAAAAAAAABI/aXhkyN7cuuk/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://jalopnik.com/ [2] => [3] => [4] => 3 ) [19] => [20] => [21] => Jalopnik: Drive Free or Die ) [3] => Array ( ) ) [5] => Array ( [0] => Array ( [0] => [1] => [2] => 105503202599719238167 ) [1] => Array ( ) [2] => Array ( [0] => Audi USA [1] => [2] => [3] => [4] => 4b14db7535e99 [5] => 8owhCkGEHmR [6] => 8owhCkGEHmR [7] => [8] => //lh3.googleusercontent.com/-mHHyVhWfARE/AAAAAAAAAAI/AAAAAAAAAC4/Qn0lYbilT8M/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.audiusa.com [2] => (800) 822-2834 [3] => [4] => 3 ) [19] => [20] => [21] => Progress is social media, and listening, and fans, and Google+. So here we are. ) [3] => Array ( ) ) [6] => Array ( [0] => Array ( [0] => [1] => [2] => 104108787932235341403 ) [1] => Array ( ) [2] => Array ( [0] => Audi Sport [1] => [2] => [3] => [4] => 4b23243c864b1 [5] => 8owhCkGAGJC8IF [6] => 8owhCkGAGJC8IF [7] => [8] => //lh4.googleusercontent.com/-jGBNL9dbwYs/AAAAAAAAAAI/AAAAAAAAAUA/pgsAqvaX8XM/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.facebook.com/AudiSportPage [2] => [3] => [4] => 6 ) [19] => [20] => [21] => Unofficial Audi Sport fan page, not affiliated with or endorsed by Audi AG. ) [3] => Array ( ) ) [7] => Array ( [0] => Array ( [0] => [1] => [2] => 106689856342933829975 ) [1] => Array ( ) [2] => Array ( [0] => Volkswagen USA [1] => [2] => [3] => [4] => 4b20ca9b7fa69 [5] => JJBxDohI8nBjFFGEHmR [6] => JJBxDohI8nBjFFGEHmR [7] => [8] => //lh5.googleusercontent.com/-i3MO9CsymQ8/AAAAAAAAAAI/AAAAAAAAAB4/ddmTW3D8s20/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.vw.com [2] => (800) 822-8987 [3] => [4] => 3 ) [19] => [20] => [21] => Take a look around, kick the tires, ask questions and get to know our community. ) [3] => Array ( ) ) [8] => Array ( [0] => Array ( [0] => [1] => [2] => 115425298803319911308 ) [1] => Array ( ) [2] => Array ( [0] => Internal Frequency [1] => [2] => [3] => [4] => 4b177b6d46119 [5] => Co4CAo_08no3BJZjGowjFHhM [6] => Co4CAo_08no3BJZjGowjFHhM [7] => [8] => //lh4.googleusercontent.com/-lZeecuGL3Ig/AAAAAAAAAAI/AAAAAAAAABk/Afv5eGuBzUM/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.internalfrequency.com [2] => [3] => [4] => 6 ) [19] => [20] => [21] => The 1st hand ups-and-downs of the CEO of an up-and-coming entertainment label in Southern California ) [3] => Array ( ) ) [9] => Array ( [0] => Array ( [0] => [1] => [2] => 101358795463286919640 ) [1] => Array ( ) [2] => Array ( [0] => Music Think Tank [1] => [2] => [3] => [4] => 4b1947fea8251 [5] => EoxACmg3IIJrFIg3IHS0Dk [6] => EoxACmg3IIJrFIg3IHS0Dk [7] => [8] => //lh4.googleusercontent.com/-B2KTfl4uNyE/AAAAAAAAAAI/AAAAAAAAACM/N955ZhPV08E/photo.jpg [9] => [10] => 1 [11] => [12] => [13] => [14] => [15] => 0 [16] => [17] => Array ( ) [18] => Array ( [0] => [1] => http://www.musicthinktank.com [2] => [3] => [4] => 6 ) [19] => [20] => [21] => Where the music industry speaks out loud. Create the Chaos. ) [3] => Array ( ) ) ) ) ) 1 Now that is ALOT of arrays! Not only that, I only require the super nested array [2] where the name starts and of that values [0] & [8] only! Then I get an error when this next line (below) runs but I am less concerned with that, I want to know how can I trim down this data so it doesn't become such a memory hog.... $visiblepeople = $jsondata[2];
To me this looks like JSON ( http://www.json.org ), and thus, you can use any JSON implementation to parse it. For Python, there's a module called ... json ;-) See http://docs.python.org/library/json.html.
Referencing an index in an array in SMARTY template
I have a variable that is an array in Smarty, and I am trying to figure out how to retrieve that information. The variable is called $COMMENTS and I did $COMMENTS|#print_r and this is what I got: Array ( [0] => ModComments_CommentsModel Object ( [data:private] => Array ( [0] => 11686 [crmid] => 11686 [1] => 1679 [smcreatorid] => 1679 [2] => 1679 [smownerid] => 1679 [3] => 0 [modifiedby] => 0 [4] => ModComments [setype] => ModComments [5] => [description] => [6] => 2011-06-08 15:00:31 [createdtime] => 2011-06-08 15:00:31 [7] => 2011-06-08 15:00:31 [modifiedtime] => 2011-06-08 15:00:31 [8] => 2011-06-29 12:00:23 [viewedtime] => 2011-06-29 12:00:23 [9] => [status] => [10] => 0 [version] => 0 [11] => 1 [presence] => 1 [12] => 0 [deleted] => 0 [13] => 11686 [modcommentsid] => 11686 [14] => aasd [commentcontent] => aasd [15] => 6730 [related_to] => 6730 [16] => [parent_comments] => [17] => 11686 ) ) [1] => ModComments_CommentsModel Object ( [data:private] => Array ( [0] => 11685 [crmid] => 11685 [1] => 1679 [smcreatorid] => 1679 [2] => 1679 [smownerid] => 1679 [3] => 0 [modifiedby] => 0 [4] => ModComments [setype] => ModComments [5] => [description] => [6] => 2011-06-08 14:58:42 [createdtime] => 2011-06-08 14:58:42 [7] => 2011-06-08 14:58:42 [modifiedtime] => 2011-06-08 14:58:42 [8] => [viewedtime] => [9] => [status] => [10] => 0 [version] => 0 [11] => 1 [presence] => 1 [12] => 0 [deleted] => 0 [13] => 11685 [modcommentsid] => 11685 [14] => comment [commentcontent] => comment [15] => 6730 [related_to] => 6730 [16] => [parent_comments] => [17] => 11685 ) ) [2] => ModComments_CommentsModel Object ( [data:private] => Array ( [0] => 6731 [crmid] => 6731 [1] => 1679 [smcreatorid] => 1679 [2] => 1679 [smownerid] => 1679 [3] => 0 [modifiedby] => 0 [4] => ModComments [setype] => ModComments [5] => [description] => [6] => 2010-11-02 10:15:06 [createdtime] => 2010-11-02 10:15:06 [7] => 2010-11-02 10:15:06 [modifiedtime] => 2010-11-02 10:15:06 [8] => [viewedtime] => [9] => [status] => [10] => 0 [version] => 0 [11] => 1 [presence] => 1 [12] => 0 [deleted] => 0 [13] => 6731 [modcommentsid] => 6731 [14] => Test comment [commentcontent] => Test comment [15] => 6730 [related_to] => 6730 [16] => [parent_comments] => [17] => 6731 ) ) ) I am trying to retrieve the 11686 number from that. Any help? I have tried $COMMENTS[0][data:private][0] but that didn't work. Any help greatly appreciated :)
First, put print_r() output into <pre> tags so it is readable. Array ( [0] => ModComments_CommentsModel Object ( [data:private] => Array ( [0] => 11686 [crmid] => 11686 [1] => 1679 [smcreatorid] => 1679 [2] => 1679 ... ) ) ... ) You're trying to access the first object in your array, $COMMENTS[0]. Since that it is object, and your data property is private, you cannot access it in Smarty. You would have to edit the ModComments_CommentsModel class to give you access to either the data property or the crmid key of the property. Example: class ModComments_CommentsModel { // ... public function CrmId(){ return $this->data['crmid']; } // ... } {* template *} {$COMMENTS[0]->CrmId()} {* might have to assign before using method call *} {assign var='comment' value=$COMMENTS[0]} {$comment->CrmId()}