Php array saving values only till 62 indices - php

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
)

Related

Create a new array from a multidimensional array by those arrays have same length in php

I've a multidimensional array looks like below-
Array
(
[0] => Array
(
[0] => Account Number
[1] => Account Title
[2] => Account Type
[3] => Currency
[4] => Available Balance
[5] => Ledger Balance
)
[1] => Array
(
[0] => xxxxxxxx YYYYYYY
)
[2] => Array
(
[0] =>
)
[3] => Array
(
[0] => Date
[1] => Description
[2] => Withdrawal
[3] => Deposit
[4] => Balance
)
[4] => Array
(
[0] =>
)
[5] => Array
(
[0] => `30/08/2018
[1] => EXIM 5287609
[2] => -
[3] => 25000.00
[4] => 62672.880
)
[6] => Array
(
[0] => `03/09/2018
[1] => PRIME 9373059
[2] => -
[3] => 191920.00
[4] => 254592.880
)
[7] => Array
(
[0] => `04/09/2018
[1] => RV CLEARING FEE-CHQ 9373059
[2] => 8.70
[3] => -
[4] => 254584.180
)
[8] => Array
(
[0] => `04/09/2018
[1] => VAT AT SOURCE
[2] => 1.30
[3] => -
[4] => 254582.880
)
[9] => Array
(
[0] => `04/09/2018
[1] => ATM WDR AT 4503 13:55:02
[2] => 20000.00
[3] => -
[4] => 234582.880
)
[10] => Array
(
[0] => `08/09/2018
[1] => ATM WDR AT 4504 11:58:19
[2] => 10000.00
[3] => -
[4] => 224582.880
)
[11] => Array
(
[0] => `09/09/2018
[1] => ATM WDR AT 4500 20:05:19
[2] => 40000.00
[3] => -
[4] => 184582.880
)
[12] => Array
(
[0] => `09/09/2018
[1] => ATM WDR AT 4500 20:05:59
[2] => 40000.00
[3] => -
[4] => 144582.880
)
[13] => Array
(
[0] => `09/09/2018
[1] => ATM WDR AT 4500 20:06:37
[2] => 20000.00
[3] => -
[4] => 124582.880
)
[14] => Array
(
[0] => `12/09/2018
[1] => B ASIA 5904486
[2] => -
[3] => 490000.00
[4] => 614582.880
)
[15] => Array
(
[0] => `12/09/2018
[1] => B ASIA 5904486 RETURN
[2] => 490000.00
[3] => -
[4] => 124582.880
)
[16] => Array
(
[0] => `12/09/2018
[1] => RV CLEARING FEE-CHQ 5904486
[2] => 8.70
[3] => -
[4] => 124574.180
)
[17] => Array
(
[0] => `12/09/2018
[1] => VAT AT SOURCE
[2] => 1.30
[3] => -
[4] => 124572.880
)
[18] => Array
(
[0] => `12/09/2018
[1] => ATM WDR AT 4500 12:31:55
[2] => 20000.00
[3] => -
[4] => 104572.880
)
[19] => Array
(
[0] => `13/09/2018
[1] => ATM WDR AT 4503 14:59:28
[2] => 20000.00
[3] => -
[4] => 84572.880
)
[20] => Array
(
[0] => `16/09/2018
[1] => ATM WDR AT 4500 17:10:04
[2] => 10000.00
[3] => -
[4] => 74572.880
)
[21] => Array
(
[0] => `19/09/2018
[1] => B ASIA 5904486
[2] => -
[3] => 490000.00
[4] => 564572.880
)
[22] => Array
(
[0] => `19/09/2018
[1] => ATM WDR AT 4502 16:24:29
[2] => 40000.00
[3] => -
[4] => 524572.880
)
[23] => Array
(
[0] => `19/09/2018
[1] => ATM WDR AT 4502 16:25:12
[2] => 10000.00
[3] => -
[4] => 514572.880
)
[24] => Array
(
[0] => `20/09/2018
[1] => B ASIA 5904486 RETURN
[2] => 490000.00
[3] => -
[4] => 24572.880
)
[25] => Array
(
[0] => `20/09/2018
[1] => RV CLEARING FEE-CHQ 5904486
[2] => 8.70
[3] => -
[4] => 24564.180
)
[26] => Array
(
[0] => `20/09/2018
[1] => VAT AT SOURCE
[2] => 1.30
[3] => -
[4] => 24562.880
)
[27] => Array
(
[0] => `22/09/2018
[1] => ATM WDR AT 4500 14:09:11
[2] => 15000.00
[3] => -
[4] => 9562.880
)
[28] => Array
(
[0] => `24/09/2018
[1] => CASH DEPOSIT
[2] => -
[3] => 100000.00
[4] => 109562.880
)
[29] => Array
(
[0] => `25/09/2018
[1] => EFT TO PRIME BANK LT
[2] => 45000.00
[3] => -
[4] => 64562.880
)
[30] => Array
(
[0] => `26/09/2018
[1] => ATM WDR AT 4503 11:06:25
[2] => 5000.00
[3] => -
[4] => 59562.880
)
)
Now I need a new array looks like below-
array(
[1] => Array
(
[0] => Date
[1] => Description
[2] => Withdrawal
[3] => Deposit
[4] => Balance
)
[2] => Array
(
[0] => `30/08/2018
[1] => EXIM 5287609
[2] => -
[3] => 25000.00
[4] => 62672.880
)
[3] => Array
(
[0] => `03/09/2018
[1] => PRIME 9373059
[2] => -
[3] => 191920.00
[4] => 254592.880
)
[4] => Array
(
[0] => `04/09/2018
[1] => RV CLEARING FEE-CHQ 9373059
[2] => 8.70
[3] => -
[4] => 254584.180
)
[5] => Array
(
[0] => `04/09/2018
[1] => VAT AT SOURCE
[2] => 1.30
[3] => -
[4] => 254582.880
)
[6] => Array
(
[0] => `04/09/2018
[1] => ATM WDR AT 4503 13:55:02
[2] => 20000.00
[3] => -
[4] => 234582.880
)
[7] => Array
(
[0] => `08/09/2018
[1] => ATM WDR AT 4504 11:58:19
[2] => 10000.00
[3] => -
[4] => 224582.880
)
[8] => Array
(
[0] => `09/09/2018
[1] => ATM WDR AT 4500 20:05:19
[2] => 40000.00
[3] => -
[4] => 184582.880
)
[9] => Array
(
[0] => `09/09/2018
[1] => ATM WDR AT 4500 20:05:59
[2] => 40000.00
[3] => -
[4] => 144582.880
)
[10] => Array
(
[0] => `09/09/2018
[1] => ATM WDR AT 4500 20:06:37
[2] => 20000.00
[3] => -
[4] => 124582.880
)
[11] => Array
(
[0] => `12/09/2018
[1] => B ASIA 5904486
[2] => -
[3] => 490000.00
[4] => 614582.880
)
[12] => Array
(
[0] => `12/09/2018
[1] => B ASIA 5904486 RETURN
[2] => 490000.00
[3] => -
[4] => 124582.880
)
[13] => Array
(
[0] => `12/09/2018
[1] => RV CLEARING FEE-CHQ 5904486
[2] => 8.70
[3] => -
[4] => 124574.180
)
[14] => Array
(
[0] => `12/09/2018
[1] => VAT AT SOURCE
[2] => 1.30
[3] => -
[4] => 124572.880
)
[15] => Array
(
[0] => `12/09/2018
[1] => ATM WDR AT 4500 12:31:55
[2] => 20000.00
[3] => -
[4] => 104572.880
)
[16] => Array
(
[0] => `13/09/2018
[1] => ATM WDR AT 4503 14:59:28
[2] => 20000.00
[3] => -
[4] => 84572.880
)
[17] => Array
(
[0] => `16/09/2018
[1] => ATM WDR AT 4500 17:10:04
[2] => 10000.00
[3] => -
[4] => 74572.880
)
[18] => Array
(
[0] => `19/09/2018
[1] => B ASIA 5904486
[2] => -
[3] => 490000.00
[4] => 564572.880
)
[19] => Array
(
[0] => `19/09/2018
[1] => ATM WDR AT 4502 16:24:29
[2] => 40000.00
[3] => -
[4] => 524572.880
)
[20] => Array
(
[0] => `19/09/2018
[1] => ATM WDR AT 4502 16:25:12
[2] => 10000.00
[3] => -
[4] => 514572.880
)
[21] => Array
(
[0] => `20/09/2018
[1] => B ASIA 5904486 RETURN
[2] => 490000.00
[3] => -
[4] => 24572.880
)
[22] => Array
(
[0] => `20/09/2018
[1] => RV CLEARING FEE-CHQ 5904486
[2] => 8.70
[3] => -
[4] => 24564.180
)
[23] => Array
(
[0] => `20/09/2018
[1] => VAT AT SOURCE
[2] => 1.30
[3] => -
[4] => 24562.880
)
[24] => Array
(
[0] => `22/09/2018
[1] => ATM WDR AT 4500 14:09:11
[2] => 15000.00
[3] => -
[4] => 9562.880
)
[25] => Array
(
[0] => `24/09/2018
[1] => CASH DEPOSIT
[2] => -
[3] => 100000.00
[4] => 109562.880
)
[26] => Array
(
[0] => `25/09/2018
[1] => EFT TO PRIME BANK LT
[2] => 45000.00
[3] => -
[4] => 64562.880
)
[27] => Array
(
[0] => `26/09/2018
[1] => ATM WDR AT 4503 11:06:25
[2] => 5000.00
[3] => -
[4] => 59562.880
)
)
I know by using a loop I can separate my desired arrays and can crate a new array. But without any loop, is it possible to create a new array by PHP built in method?
Advance thanks for all of you who will give me a nice solution.
Note:- array will be too long. It's a bank transaction array so need a fast method which will give output within the shortest time.
You can filter arrays based on it length using array_filter()
$newArr = array_filter($arr, function($item){
return sizeof($item) == 5;
});
If your array is large and you need a fast method, use foreach instead
foreach ($arr as $key=>$item)
sizeof($item) != 5 ? unset($arr[$key]) : "";
All activities on one go...
$length=count($arr);
for($i=0;$i<$length;$i++){
if(count($arr[$i])==4){
// execute desired process
}
}

Retrieving elements from a nested array

I am using MultipleIterator() to iterate through two different arrays and get each element.
My code
$d = new MultipleIterator ();
$d->attachIterator ( new ArrayIterator ( $tbl_one_data ) );
$d->attachIterator ( new ArrayIterator ( $tbl_two_data ) );
foreach ( $d as $data ) {
print_r($data);
}
Which generates the following :
My question is how do I loop through the array and return each element? For example I would like to return 2014-11-06 11:31:58.781018. Tried using $data[0][0] but this returns all elements in the first index but I only want one element.
EDIT
print_r($d);
MultipleIterator Object ( [storage:SplObjectStorage:private] => Array ( [00000000583bd67b000000000ac6c449] => Array ( [obj] => ArrayIterator Object ( [storage:ArrayIterator:private] => Array ( [0] => Array ( [0] => 1 [1] => 2014-11-06 11:31:58.781018 [2] => NONE [3] => NONE ) [1] => Array ( [0] => 2 [1] => 2014-11-06 11:31:58.799436 [2] => MANAGER [3] => 500 ) [2] => Array ( [0] => 3 [1] => 2014-11-06 11:31:58.841035 [2] => MANAGER [3] => 501 ) [3] => Array ( [0] => 4 [1] => 2014-11-06 11:33:00.741873 [2] => MANAGER [3] => 500 ) [4] => Array ( [0] => 5 [1] => 2014-11-06 11:33:00.802389 [2] => MANAGER [3] => 501 ) [5] => Array ( [0] => 6 [1] => 2014-11-06 13:15:49.457646 [2] => MANAGER [3] => 500 ) [6] => Array ( [0] => 7 [1] => 2014-11-06 13:37:16.259128 [2] => NONE [3] => NONE ) [7] => Array ( [0] => 8 [1] => 2014-11-06 13:37:16.275201 [2] => NONE [3] => 500 ) [8] => Array ( [0] => 9 [1] => 2014-11-06 13:37:27.682873 [2] => NONE [3] => NONE ) [9] => Array ( [0] => 10 [1] => 2014-11-06 13:37:27.690863 [2] => NONE [3] => 500 ) [10] => Array ( [0] => 11 [1] => 2014-11-06 13:52:21.108003 [2] => MANAGER [3] => 500 ) [11] => Array ( [0] => 12 [1] => 2014-11-06 14:17:01.266769 [2] => NONE [3] => NONE ) [12] => Array ( [0] => 13 [1] => 2014-11-06 14:17:01.279507 [2] => node1-1415283420.0 [3] => 500 ) [13] => Array ( [0] => 14 [1] => 2014-11-06 14:17:02.527183 [2] => node1-1415283420.0 [3] => 500 ) [14] => Array ( [0] => 15 [1] => 2014-11-06 14:17:23.775279 [2] => node1-1415283442.1 [3] => 500 ) ) ) [inf] => ) [00000000583bd67a000000000ac6c449] => Array ( [obj] => ArrayIterator Object ( [storage:ArrayIterator:private] => Array ( [0] => Array ( [0] => NONE [1] => QUEUESTART [2] => [3] => [4] => [5] => [6] => ) [1] => Array ( [0] => Local/120#disc-agents/n [1] => ADDMEMBER [2] => [3] => [4] => [5] => [6] => ) [2] => Array ( [0] => Local/120#disc-agents/n [1] => ADDMEMBER [2] => [3] => [4] => [5] => [6] => ) [3] => Array ( [0] => Local/120#disc-agents/n [1] => REMOVEMEMBER [2] => [3] => [4] => [5] => [6] => ) [4] => Array ( [0] => Local/120#disc-agents/n [1] => REMOVEMEMBER [2] => [3] => [4] => [5] => [6] => ) [5] => Array ( [0] => Local/120#disc-agents/n [1] => ADDMEMBER [2] => [3] => [4] => [5] => [6] => ) [6] => Array ( [0] => Local/120#disc-agents/n [1] => PAUSEALL [2] => [3] => [4] => [5] => [6] => ) [7] => Array ( [0] => Dunc Test [1] => PAUSE [2] => [3] => [4] => [5] => [6] => ) [8] => Array ( [0] => Local/120#disc-agents/n [1] => UNPAUSEALL [2] => [3] => [4] => [5] => [6] => ) [9] => Array ( [0] => Dunc Test [1] => UNPAUSE [2] => [3] => [4] => [5] => [6] => ) [10] => Array ( [0] => Local/120#disc-agents/n [1] => REMOVEMEMBER [2] => [3] => [4] => [5] => [6] => ) [11] => Array ( [0] => NONE [1] => QUEUESTART [2] => [3] => [4] => [5] => [6] => ) [12] => Array ( [0] => NONE [1] => ENTERQUEUE [2] => [3] => 363 [4] => 1 [5] => [6] => ) [13] => Array ( [0] => NONE [1] => ABANDON [2] => 1 [3] => 1 [4] => 1 [5] => [6] => ) [14] => Array ( [0] => NONE [1] => ENTERQUEUE [2] => [3] => 363 [4] => 1 [5] => [6] => ) ) ) [inf] => ) ) )
if this is really output by print_r then $data[0][1] must be '2014-11-06 11:31:58.781018' . I test it by code:
$data = array(array('1','2014-11-06 11:31:58.781018'));
echo '<pre>';
print_r($data); echo '<br>';
echo 'what we want: '.$data[0][1].'<br>';
otput:
Array
(
[0] => Array
(
[0] => 1
[1] => 2014-11-06 11:31:58.781018
)
)
what we want: 2014-11-06 11:31:58.781018
If you have the $data as an array you can access the value: 2014-11-06 11:31:58.781018 by using,
$date = $data[0][1];

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.

array manipulation

I have a two column array (array1), for each row of that array I need to compare the value in the 2nd column with a column value in each row of another array(array1) , when they equal I want to append another column value (from array2) to the first array.
in english:
if array1[x][1] = array2[y][0]
then array1[x][2] = array2[y][2]
screen dumps of both arrays
array1 (
[1] => Array (
[0] => 1 [1] => 2
)
[2] => Array (
[0] => 2 [1] => 3
)
[3] => Array (
[0] => 3 [1] =>
) [7] => Array (
[0] => 7 [1] => 1
)
[8] => Array (
[0] => 8 [1] => 1
)
[9] => Array (
[0] => 9 [1] => 10
)
[10] => Array (
[0] => 10 [1] => 2
)
)
array2 (
[0] => Array (
[0] => 1
[1] => 2
[2] => 2
[3] => Jane
[4] => Smith
[5] => jsmith#internet.com
[6] => jsmith
[7] => 12345
[8] => 1
[9] => no
)
[1] => Array (
[0] => 2
[1] => 2
[2] => 3
[3] => James
[4] => Beard
[5] => jasb#bellsouth.net
[6] => jbeard03
[7] => keeper
[8] => 1
[9] => no
)
[2] => Array (
[0] => 3
[1] => 2
[2] =>
[3] => Peter
[4] => Allen
[5] => pallen#rfgg.com
[6] => pallen
[7] => pallen
[8] => 1
[9] => no
)
[3] => Array (
[0] => 7
[1] => 2
[2] => 1
[3] => Joe
[4] => Blow
[5] => jasb#bellsouth.net
[6] => jblow
[7] => blow123
[8] => 5
[9] => yes
)
[4] => Array (
[0] => 8
[1] => 2
[2] => 1
[3] => John
[4] => Smith
[5] => logtest#bellsouth.net
[6] => jnsmith
[7] => jsmith123
[8] => 4
[9] => yes
)
[5] => Array (
[0] => 9
[1] => 2
[2] => 10
[3] => Frank
[4] => Smith
[5] => pallen#test.com
[6] => fsmith
[7] => fsmith123
[8] => 4
[9] => yes
)
[6] => Array (
[0] => 10
[1] => 2
[2] => 2
[3] => Loretta
[4] => Beard
[5] => lbeard#me.net
[6] => lbeard
[7] => lbeard123
[8] => 1
[9] => no
)
)
Does this work? I'm not sure I'm entirely clear on what you're looking for.
foreach($array1 as $x => $xarray) {
foreach($array2 as $y => $yarray) {
if($xarray[1] == $yarray[0]) {
$array1[$x][2] = $array[$y][2];
}
}
}
foreach ($array1 as &$a1) {
foreach ($array2 as $a2) {
if ($a1[1] == $a2[0]) {
$a1[] = $a2[2];
continue 2;
}
}
}
BTW, you should try to use explicit keys that actually mean something, e.g. $a1['id'] instead of $a1[1]. You'll thank yourself when you look at the code again two months down the road.
And because I threatened to do so:
btwyoushouldtrytouseexplicitkeysthatactuallymeansomethingeg$a1['id']insteadof$a1[1]youllthankyourselfwhenyoulookatthecodeagaintwomonthsdowntheroad ;-P

Categories