How to Change XLXS excel data into a multidimensional array - php

enter image description here
How can I convert this XLXS excel file into following array format. Also I attached the Screenshot of Excel file. Please review it and let me know
I am using this library to fetch the data from Excel file which i have mentioned given below:-
require_once "EXCEL/simplexlsx.class.php";
$xlsx = new SimpleXLSX('EXCEL/Testingexcel.xlsx');
Excel Array
$xlsx->rows()
Array
(
[0] => Array
(
[0] => Section / Department
1 => Notes
[2] => No
[3] => Great Offer
[4] => Code
[5] => Use Photo
[6] => Item Number
[7] => English Description
[8] => Greek Description
[9] => Price From
[10] => Price
[11] => Text1
[12] => Exclusive Brand
[13] => Date From
[14] => Date To
)
[1] => Array
(
[0] => Chair
[1] => Cover
[2] => 1
[3] =>
[4] =>
[5] =>
[6] =>
[7] => etge
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[2] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP1
[5] =>
[6] =>
[7] => wefewf
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[3] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP2
[5] =>
[6] =>
[7] => TITLE 1
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[4] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP3
[5] =>
[6] =>
[7] => TITLE 12
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[5] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP4
[5] =>
[6] =>
[7] => TITLE 13
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[6] => Array
(
[0] =>
[1] =>
[2] => 2
[3] =>
[4] => AP5
[5] =>
[6] =>
[7] => TITLE 14
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[7] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP6
[5] =>
[6] =>
[7] => TITLE 15
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[8] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP7
[5] =>
[6] =>
[7] => TITLE 16
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[9] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP8
[5] =>
[6] =>
[7] => TITLE 17
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[10] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP9
[5] => Y
[6] =>
[7] => TITLE 18
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[11] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP10
[5] =>
[6] =>
[7] => TITLE 19
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[12] => Array
(
[0] => Table
[1] => cover
[2] => 2
[3] =>
[4] =>
[5] =>
[6] =>
[7] => TITLE 20
[8] =>
[9] =>
[10] =>
[11] => 1+1
[12] =>
[13] =>
[14] =>
)
[13] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP11
[5] =>
[6] =>
[7] => TITLE 145
[8] =>
[9] =>
[10] =>
[11] => 1+1
[12] =>
[13] =>
[14] =>
)
[14] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP12
[5] =>
[6] =>
[7] => TITLE 1657
[8] =>
[9] =>
[10] =>
[11] => 1+1
[12] =>
[13] =>
[14] =>
)
[15] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
)
[16] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
)
[17] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
)
)
foreach ($xlsx->rows() as $key => $valueRows){
}
Array [0] => Array
(
[chair] => Array
(
[offer 1] => Array
(
[0] => AP1
[1] => AP2
[2] => AP3
[3] => AP4
)
[offer 2] => Array
(
[0] => AP5
[1] => AP6
[2] => AP7
[3] => AP8
[4] => AP9
)
)
[table] => Array
(
[offer 1] => Array
(
[0] => AP10
)
)
)

Related

Glob patterns for file matching in PHP - Get directory contents which do not start with a string group

How can I ignore all images that begin with the string 'blogCover'?
At first I did not exclude a picture for the test
all pictures in img directory:
$imgDir = 'img';
$imgs = glob($imgDir.'/*{.jpg}', GLOB_BRACE); //all images!
echo'<pre>'; print_r($imgs); echo'</pre>';
result:
Array
(
[0] => img/blogCover-large.jpg
[1] => img/blogCover-large_2x.jpg
[2] => img/blogCover-medium.jpg
[3] => img/blogCover-medium_2x.jpg
[4] => img/blogCover-small.jpg
[5] => img/blogCover-small_2x.jpg
[6] => img/boddy-large.jpg
[7] => img/boddy-large_2x.jpg
[8] => img/boddy-medium.jpg
[9] => img/boddy-medium_2x.jpg
[10] => img/boddy-small.jpg
[11] => img/boddy-small_2x.jpg
[12] => img/face-large.jpg
[13] => img/face-large_2x.jpg
[14] => img/face-medium.jpg
[15] => img/face-medium_2x.jpg
[16] => img/face-small.jpg
[17] => img/face-small_2x.jpg
[18] => img/hand-large.jpg
[19] => img/hand-large_2x.jpg
[20] => img/hand-medium.jpg
[21] => img/hand-medium_2x.jpg
[22] => img/hand-small.jpg
[23] => img/hand-small_2x.jpg
[24] => img/head-large.jpg
[25] => img/head-large_2x.jpg
[26] => img/head-medium.jpg
[27] => img/head-medium_2x.jpg
[28] => img/head-small.jpg
[29] => img/head-small_2x.jpg
)
my goal: Ignore all images that begin with the string 'blogCover'
$imgDir = 'img';
$imgs = glob($imgDir.'/*{[!blogCover*].jpg}', GLOB_BRACE);
echo'<pre>'; print_r($imgs); echo'</pre>';
unexpected result:
Array
(
[0] => img/blogCover-large_2x.jpg
[1] => img/blogCover-medium.jpg
[2] => img/blogCover-medium_2x.jpg
[3] => img/blogCover-small_2x.jpg
[4] => img/boddy-large_2x.jpg
[5] => img/boddy-medium.jpg
[6] => img/boddy-medium_2x.jpg
[7] => img/boddy-small_2x.jpg
[8] => img/face-large_2x.jpg
[9] => img/face-medium.jpg
[10] => img/face-medium_2x.jpg
[11] => img/face-small_2x.jpg
[12] => img/hand-large_2x.jpg
[13] => img/hand-medium.jpg
[14] => img/hand-medium_2x.jpg
[15] => img/hand-small_2x.jpg
[16] => img/head-large_2x.jpg
[17] => img/head-medium.jpg
[18] => img/head-medium_2x.jpg
[19] => img/head-small_2x.jpg
)
all '* -large.jpg', '* -small.jpg' images are missing
expected result:
Array
(
[0] => img/boddy-large.jpg
[1] => img/boddy-large_2x.jpg
[2] => img/boddy-medium.jpg
[3] => img/boddy-medium_2x.jpg
[4] => img/boddy-small.jpg
[5] => img/boddy-small_2x.jpg
[6] => img/face-large.jpg
[7] => img/face-large_2x.jpg
[8] => img/face-medium.jpg
[9] => img/face-medium_2x.jpg
[10] => img/face-small.jpg
[11] => img/face-small_2x.jpg
[12] => img/hand-large.jpg
[13] => img/hand-large_2x.jpg
[14] => img/hand-medium.jpg
[15] => img/hand-medium_2x.jpg
[16] => img/hand-small.jpg
[17] => img/hand-small_2x.jpg
[18] => img/head-large.jpg
[19] => img/head-large_2x.jpg
[20] => img/head-medium.jpg
[21] => img/head-medium_2x.jpg
[22] => img/head-small.jpg
[23] => img/head-small_2x.jpg
)
I expect to ignore these pictures:
blogCover-large.jpg
blogCover-large_2x.jpg
blogCover-medium.jpg
blogCover-medium_2x.jpg
blogCover-small.jpg
blogCover-small_2x.jpg
The right syntax is:
$imgs = glob($imgDir.'/[^blogCover]*.jpg', GLOB_BRACE);

Enjin API (JSON) to PHP part 2

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'];

How to group and calculate value array when found same two keys array

I have php array like this:
Array (
[0] => Array ([electronics] => TV [condition] => GOOD [1] => 100 [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
[1] => Array ([electronics] => TV [condition] => NOTGOOD [1] => 50 [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
[2] => Array ([electronics] => AC [condition] => GOOD [1] => 200 [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
[3] => Array ([electronics] => TV [condition] => GOOD [1] => 50 [2] => 30 [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
[4] => Array ([electronics] => AC [condition] => GOOD [1] => 50 [2] => 30 [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
)
Then I want to group and calculation by [electronics] and [condition].
(calculated when found same [electronics] and [condition] in that array).
And the result I want like this:
Array (
[0] => Array ([electronics] => TV [condition] => GOOD [1] => 150 [2] => 30 [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
[1] => Array ([electronics] => TV [condition] => NOTGOOD [1] => 50 [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
[2] => Array ([electronics] => AC [condition] => GOOD [1] => 250 [2] => 30 [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => )
)
This should be one way to do it:
$result = array();
foreach ($arrays as $array) {
$key = $array['electronics'] . $array['condition'];
foreach ($array as $k => $v) {
if (is_numeric($k)) {
$result[$key][$k] += $v;
} else {
$result[$key][$k] = $v;
}
}
}
$result = array_values($result);

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.

PHP Accessing decoded JSON

I have a PHP script which successfully decodes a JSON string into a PHP object using:
$decodedJSON = json_decode($responseString);
And when $decodedJSON is printed to the response, I get:
stdClass Object
(
[response] => stdClass Object
(
[total_rows] => 2379
[data] => Array
(
[0] => Array
(
[0] => zPKfssdfg456hwCQp6XpogfTsjc
[1] => 3456gg4-b7ea-4bcf1680c619
[2] => Title Description Here.
[3] => Example Address
[4] =>
[5] =>
[6] => Exmaple City
[7] => CA
[8] => US
[9] => 95616
[10] => (555) 555-1212
[11] =>
[12] => Food & Beverage
[13] =>
[14] =>
[15] => 62.79901
[16] => -92.80102
[17] => 1
)
[1] => Array
(
[0] => zPKfl6ylrwCQp6XpogfTsjc
[1] => 98e9945a-b7ea-4bcf1680c619
[2] => Title Description Here.
[3] => Example Address
[4] =>
[5] =>
[6] => Exmaple City
[7] => CA
[8] => US
[9] => 95616
[10] => (555) 555-1212
[11] =>
[12] => Food & Beverage
[13] =>
[14] =>
[15] => 62.79901
[16] => -92.80102
[17] => 1
)
)
[fields] => Array
(
[0] => subject_key
[1] => factual_id
[2] => name
[3] => address
[4] => address_extended
[5] => po_box
[6] => locality
[7] => region
[8] => country
[9] => postcode
[10] => tel
[11] => fax
[12] => category
[13] => website
[14] => email
[15] => latitude
[16] => longitude
[17] => status
)
[rows] => 10
[cache-state] => CACHED
[big-data] => 1
[subject_columns] => Array
(
[0] => 1
)
)
[version] => 2
[status] => ok
)
My question is this: how do I access the "fields" data? I've tried using $decodedJSON["fields"] as well as $decodedJSON[0]["fields"] and $decodedJSON[0][2] and many many more variations.
Does anyone see what I am doing wrong?
Many thanks,
Brett
Try using $decodedJSON->response->fields
Well you can decode it to an associated array:
$decodedJSON = json_decode($responseString, true);
and then you can access as you were trying
OR: $decodedJSON->response->fields

Categories