I have an array of customers/people with a subarray of projects pertaining to that customer. Projects come in two types "typeJob" or "typePipeline". I need to sum the values of individual columns in the projects subarray (specifically columns 5, 6, 7 - representing revenue for month 1, month 2, and month 3) by Client.
I have tried various possible avenues including the one below, but I seem to always end up either testing if the condition is satisfied for the array as a whole rather than for each row - or if I go the way of for each loops generate errors because either there's an array/single value mismatch or the condition just doesn't do anything.
Here is what I have tried most recently. It works in the sense that it checks if "typeJob" is in the array but then sums all rows (even those without "typeJob") if "typeJob" is found for any of the Client's projects. I want to exclude rows where "typeJob" is not found.
foreach ($arrays as $row) {
$indexJob = array_search('typeJob', array_column($row['projects'],0));
if ($indexJob !== false) {
$job_total1[$row['Client']] = array_sum(array_column($row['projects'],5));
$job_total2[$row['Client']] = array_sum(array_column($row['projects'],6));
$job_total3[$row['Client']] = array_sum(array_column($row['projects'],7));
}
}
And here is the array:
(
[331] => Array
(
[KeyAccountID] => 1234
[KeyAccountName] => John Lennon
[ClientID] => 9999
[Client] => BBC
[projects] => Array
(
[0] => Array
(
[0] => typePipeline
[1] => 915
[2] => Zyxeldy
[3] =>
[4] =>
[5] => 15000
[6] =>
[7] =>
[8] =>
)
[1] => Array
(
[0] => typeJob
[1] => 956
[2] => Awesome project, Step 1
[3] =>
[4] =>
[5] => 1833.3333
[6] => 1833.3333
[7] => 1833.3333
[8] =>
)
[2] => Array
(
[0] => typePipeline
[1] => 957
[2] => Awesome project, Step 2
[3] =>
[4] =>
[5] => 7000
[6] =>
[7] =>
[8] =>
)
)
)
[344] => Array
(
[KeyAccountID] => 1234
[KeyAccountName] => John Lennon
[ClientID] => 9998
[Client] => ABC
[projects] => Array
(
[0] => Array
(
[0] => typePipeline
[1] => 487
[2] => CRM integration
[3] =>
[4] =>
[5] =>
[6] => 98750
[7] => 98750
[8] =>
)
[1] => Array
(
[0] => typeJob
[1] => 839
[2] => Data Warehouse
[3] =>
[4] =>
[5] =>
[6] => 11643.0601
[7] =>
[8] =>
)
)
)
[350] => Array
(
[KeyAccountID] => 1236
[KeyAccountName] => Ringo Starr
[ClientID] => 9997
[Client] => XYY
[projects] => Array
(
[0] => Array
(
[0] => typeJob
[1] => 867
[2] => Data Mining
[3] =>
[4] =>
[5] => 10000
[6] =>
[7] =>
[8] =>
)
)
)
[351] => Array
(
[KeyAccountID] => 1235
[KeyAccountName] => Poul McCartney
[ClientID] => 9996
[Client] => XYZ
[projects] => Array
(
[0] => Array
(
[0] => typePipeline
[1] => 715
[2] => XYZ, CSM
[3] =>
[4] =>
[5] => 22083.3333
[6] => 22083.3333
[7] => 22083.3333
[8] =>
)
)
)
etc.
You could filter the $row['projects'] array before summing the values:
foreach ($arrays as $row) {
$typeJobs = array_filter($row['projects'], function ($v) { return $v[0] == 'typeJob'; });
$job_total1[$row['Client']] = array_sum(array_column($typeJobs,5));
$job_total2[$row['Client']] = array_sum(array_column($typeJobs,6));
$job_total3[$row['Client']] = array_sum(array_column($typeJobs,7));
}
It may be quicker to just loop through them and keep a running total...
foreach ($arrays as $row) {
$totals = [0,0,0];
foreach ( $row['projects'] as $project ) {
if ( $project[0] == 'typeJob' ) {
$totals[0] += $project[5];
$totals[1] += $project[6];
$totals[2] += $project[7];
}
}
$job_total1[$row['Client']] = $totals[0];
$job_total2[$row['Client']] = $totals[1];
$job_total3[$row['Client']] = $totals[2];
}
it doesn't look as slim as using the array_... methods, but this only processes the array once instead of once for each call.
Related
Assume that I have two multidimensional arrays as follows:
Multidimensional array 1:
$newArray = Array
(
[0] => Array
(
[0] => 45521
[1] => Clothing
[2] => Percent discount
[3] => Get 15% off With Code ABCD15
[4] => 2020-05-18
[5] => 2020-05-31
[6] => ABCD15
[7] => https://domain[dot]com/AYuANDEqU40
[8] => Boutique
[9] => Germany
)
[1] => Array
(
[0] => 45516
[1] => Apparel
[2] => Percentage Off
[3] => 15% off With Code ABCD15
[4] => 2020-05-18
[5] => 2020-05-31
[6] => ABCD15
[7] => https://domain[dot]com/AYuANDEqU40
[8] => Boutique
[9] => Australia
)
[2] => Array
(
[0] => 45672
[1] => Food & Drink
[2] => Free Shipping
[3] => Summer Collection Now. Shop Now!
[4] => 2020-05-17
[5] => 2020-08-01
[6] => N/A
[7] => https://domain[dot]com/AYuANDEqU40761312
[8] => Fancy
[9] => US
)
[3] => Array
(
[0] => 45866
[1] => Food & Drink
[2] => Percentage off
[3] => 20% Off
[4] => 2020-05-17
[5] => 2026-05-15
[6] => OFF20
[7] => https://domain[dot]com/AYuANDEqU40780908
[8] => Biata
[9] => US
)
[4] => Array
(
[0] => 45524
[1] => Health & Wellness
[2] => Other
[3] => Jet's monthly bottle of probiotics. Try it now!
[4] => 2020-05-02
[5] => 2026-05-01
[6] => N/A
[7] => https://domain[dot]com/AYuANDEqU40758409
[8] => Jet
[9] => US
)
)
[5] => Array
(
[0] => 45524
[1] => Health & Wellness
[2] => Other
[3] => Jet seasonal probiotics. No hidden cost.
[4] => 2020-05-02
[5] => 2026-05-01
[6] => N/A
[7] => https://domain[dot]com/AYuANDEqU40758408
[8] => Jet
[9] => US
)
Multidimension array 2:
$oldArray = Array
(
[0] => Array
(
[0] => 45521
[1] => Clothing's
[2] => Percent discount
[3] => Get 15% off With Code ABCD15
[4] => 2020-05-18
[5] => 2020-05-31
[6] => ABCD15
[7] => https://domain[dot]com/AYuANDEqU40
[8] => Boutique
[9] => Germany
)
[1] => Array
(
[0] => 45516
[1] => Apparel
[2] => Percentage Off
[3] => 15% off With Code ABCD15
[4] => 2020-05-18
[5] => 2020-05-31
[6] => ABCD15
[7] => https://domain[dot]com/AYuANDEqU40
[8] => Boutique
[9] => Australia
)
[2] => Array
(
[0] => 45672
[1] => Food & Drink
[2] => Free Shipping
[3] => Summer Collection Now. Shop Now!
[4] => 2020-05-17
[5] => 2020-08-01
[6] => N/A
[7] => https://domain[dot]com/AYuANDEqU40761312
[8] => Fancy
[9] => US
)
[3] => Array
(
[0] => 45866
[1] => Food & Drink
[2] => Percentage off
[3] => 20% Off
[4] => 2020-05-17
[5] => 2026-05-15
[6] => OFF20
[7] => https://domain[dot]com/AYuANDEqU40780908
[8] => Biata
[9] => US
)
[4] => Array
(
[0] => 45706
[1] => Electronic Equipment
[2] => Percentage off
[3] => 40% Off-Set Under $200!
[4] => 2020-05-17
[5] => 2026-05-15
[6] => N/A
[7] => https://domain[dot]com/AYuANDEqU40768379
[8] => GVM
[9] => US
)
)
You can easily see that the $newArray has one different array([4]) from the $oldArray, and one new array([5]) to the $oldArray, and one different key=value pair like [1] => Clothing's from the $oldArray
What i am expecting is to compare the $newArray with the $oldArray to get the different array([4]) and the new one array([5]) in the $newArray only.
I have searched for these links:
https://www.php.net/manual/en/function.array-diff-assoc.php
and
https://www.w3schools.com/php/func_array_diff_assoc.asp
but they do not help.
Then I've searched for the function in this link:
Compare two different multidimentional arrays and highlight the changes
The function:
function arrayRecursiveDiff($aArray1, $aArray2) {
$aReturn = array();
foreach ($aArray1 as $mKey => $mValue) {
if (array_key_exists($mKey, $aArray2)) {
if (is_array($mValue)) {
$aRecursiveDiff = arrayRecursiveDiff($mValue, $aArray2[$mKey]);
if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff;
}
} else {
if ($mValue != $aArray2[$mKey]) {
$aReturn[$mKey] = $mValue;
}
}
} else {
$aReturn[$mKey] = $mValue;
}
}
return $aReturn;
}
$arr1 = arrayRecursiveDiff($newentry,$oldentry);
It filters and shows me both the COMPLETE new arrays from the $newArray and the new arrays from the $newArray with only the key=value pairs that are different from the $oldArray.
Yes and again, what i am expecting is to compare the $newArray with the $oldArray to get:
1/ The COMPLETE different array like array([4]) from the $newArray.
2/ The new array like array([5]) from the $newArray.
3/ The arrays from the $newArray of which one of the key=value pairs is different from that of the $oldArray, but it must print all 9 key=value pairs of that array, which is the array[0] in this example. I don't want to get the new arrays from $newArray with the output of ONLY the updated key=value pairs.
Sorry for a long post with wordy explanation, but I have no choice.
Your help is appreciated.
$a1=array(1,2,3);
$a2=array(1,2,4);
$i =0;
$diff_Value = '';
foreach( $a1 as $val )
{
if($a2[$i]!=$val){
$diff_Value.= $val.','.$a2[$i];
}
$i =$i+1;
}
echo $diff_Value;
This pertains to PHP.
I have an array of arrays that is a recordset from a db query:
Array
(
[0] => Array
(
[0] => Amazon
[1] => AmazonSendTracking
[2] =>
[3] => 1
[4] => IN
[5] => 2020-01-07 11:32:18
[6] => 7
[7] => 5
)
[1] => Array
(
[0] => Amazon
[1] => AmazonGetOrdersAndMove
[2] =>
[3] => 4
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 6
[7] => 4
)
[2] => Array
(
[0] => Test
[1] => RedirectTest1
[2] => data=data1&data2=data2&testvar=testvariable
[3] => 4
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 19
[7] => 17
)
[3] => Array
(
[0] => Test
[1] => RedirectTest2
[2] => data=value&data2=value2&testvar=value3
[3] => 4
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 19
[7] => 25
)
[4] => Array
(
[0] => Amazon
[1] => AmazonPushInventory
[2] =>
[3] => 15
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 27
[7] => 26
)
[5] => Array
(
[0] => Amazon
[1] => CalculateFloorCeiling
[2] =>
[3] => 15
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 27
[7] => 27
)
[6] => Array
(
[0] => Amazon
[1] => AmazonSubmitPricingXML
[2] =>
[3] => 15
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 27
[7] => 28
)
[7] => Array
(
[0] => Amazon
[1] => AmazonSubmitPricingXMLResetBusinessAndFlipEm
[2] =>
[3] => 1440
[4] => OUT
[5] =>
[6] => 8
[7] => 6
)
)
the Value in the 7th position (6) of the sub-array represents a "group" that I want to break out into individual arrays.
So I want the above to become one array of items not in any group and then a new array for each group like this:
Array1 - All Items not in a group
Array1
(
[0] => Array
(
[0] => Amazon
[1] => AmazonSendTracking
[2] =>
[3] => 1
[4] => IN
[5] => 2020-01-07 11:32:18
[6] => 7
[7] => 5
)
[1] => Array
(
[0] => Amazon
[1] => AmazonGetOrdersAndMove
[2] =>
[3] => 4
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 6
[7] => 4
)
[2] => Array
(
[0] => Amazon
[1] => AmazonSubmitPricingXMLResetBusinessAndFlipEm
[2] =>
[3] => 1440
[4] => OUT
[5] =>
[6] => 8
[7] => 6
)
)
Array2 - 1st group
Array2(
[0] => Array
(
[0] => Test
[1] => RedirectTest1
[2] => data=data1&data2=data2&testvar=testvariable
[3] => 4
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 19
[7] => 17
)
[1] => Array
(
[0] => Test
[1] => RedirectTest2
[2] => data=value&data2=value2&testvar=value3
[3] => 4
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 19
[7] => 25
)
)
Array3 - 2nd group
Array3(
[0] => Array
(
[0] => Amazon
[1] => AmazonPushInventory
[2] =>
[3] => 15
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 27
[7] => 26
)
[1] => Array
(
[0] => Amazon
[1] => CalculateFloorCeiling
[2] =>
[3] => 15
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 27
[7] => 27
)
[2] => Array
(
[0] => Amazon
[1] => AmazonSubmitPricingXML
[2] =>
[3] => 15
[4] => ALL
[5] => 2020-01-07 11:32:18
[6] => 27
[7] => 28
)
)
Im just not sure what array functions would be best used to accomplish this. I have tried getting the count of each group using the following.
I have a loop that steps through the master array (array of arrays call $rs) and while in the loop I pull out the 7th position into a variable called $HeaderRecNbr and then do this:
$GroupCount=array_count_values(array_column($rs, 6))[$HeaderRecNbr];
but Im not sure where to go from here.
Just create an array indexed by the group from index 6. This will create a sub-array for each group indexed by the group number:
foreach($array as $v) {
$groups[$v[6]][] = $v;
}
Then to get the items that are alone in a group, check if there is exactly one sub-array and add it to another array. Then remove it from the group array:
foreach($groups as $k => $v) {
if(count($v) == 1) {
$other[] = $v; // or $other[$v[0][6]][] = $v;
unset($groups[$k]);
}
}
$mainArray = ... all rows variable here..
$groupedArray = [];
$countArray = [];
foreach ($mainArray as $k => $v) {
$groupedArray[$v[6]][] = $v;
$countArray[$v[6]]++;
}
$singleItems = [];
$multipleItems = [];
foreach ($groupedArray as $k => $v) {
if ($countArray[$k] > 1) $multipleItems[] = $v;
else $singleItems = $v;
}
... do something with single and multi - groups...
1: start by grouping all items in groups by the 6th item of sub array... keep count of them at same time
2. Separate single and multiple items groups in 2 arrays...
3. Do whatever you need with multi-items groups.
This function will group them by desired index, then combine the ones that dont have any other with same index, and return an array of arrays, ungrouped, then all grouped.
function sortByIndex( $data, $index ) {
$sortedData = array();
$ungroupedData = array();
// Make sure you can loop through
if ( ! is_array( $data ) ) {
return FALSE;
}
foreach ( $data as $key => $arrayToInspect ) {
if ( ! isset( $sortedData[$arrayToInspect[$index]] ) ) {
$sortedData[$arrayToInspect[$index]] = array();
}
$sortedData[$arrayToInspect[$index]][] = $arrayToInspect;
}
// Combine as desired
foreach ( $sortedData as $groupId => $data ) {
if ( count( $data ) < 2 ) {
$ungroupedData[] = $data;
unset( $sortedData[$groupId] );
}
}
return ( array_merge( [ $ungroupedData ], array_values( $sortedData ) ) );
}
I am building a jquery flot line chart with google analytics api data. I have the analytics working and it is giving me an array like so:
[3] => Array ( [0] => 20160922 [1] => 2217 [2] => 911 ) [4] => Array ( [0] => 20160923 [1] => 2047 [2] => 845 ) [5] => Array ( [0] => 20160924 [1] => 2152 [2] => 924 ) [6] => Array ( [0] => 20160925 [1] => 2502 [2] => 1028 ) [7] => Array ( [0] => 20160926 [1] => 2234 [2] => 877 ) [8] => Array ( [0] => 20160927 [1] => 2020 [2] => 755 ) [9] => Array ( [0] => 20160928 [1] => 1978 [2] => 793 ) [10] => Array ( [0] => 20160929 [1] => 2080 [2] => 867 ) [11] => Array ( [0] => 20160930 [1] => 1632 [2] => 747 ) [12] => Array ( [0] => 20161001 [1] => 1934 [2] => 913 ) [13] => Array ( [0] => 20161002 [1] => 2210 [2] => 1023 ) [14] => Array ( [0] => 20161003 [1] => 2068 [2] => 971 ) [15] => Array ( [0] => 20161004 [1] => 1738 [2] => 918 ) [16] => Array ( [0] => 20161005 [1] => 1787 [2] => 793 ) [17] => Array ( [0] => 20161006 [1] => 1694 [2] => 815 ) [18] => Array ( [0] => 20161007 [1] => 1583 [2] => 813 ) [19] => Array ( [0] => 20161008 [1] => 1906 [2] => 954 ) [20] => Array ( [0] => 20161009 [1] => 1936 [2] => 1047 ) [21] => Array ( [0] => 20161010 [1] => 2188 [2] => 1097 ) [22] => Array ( [0] => 20161011 [1] => 1892 [2] => 938 ) [23] => Array ( [0] => 20161012 [1] => 2036 [2] => 1022 ) [24] => Array ( [0] => 20161013 [1] => 1970 [2] => 915 ) [25] => Array ( [0] => 20161014 [1] => 2044 [2] => 1024 )
I cant seem to figure out how to get this separated out to use in a jquery.flot chart. The above array has a date followed by visits and pageviews that I want to put into a line-chart. All i need help with is the separating of the above array into one for visits and one for pageviews. The rest I can work out. Any help to get me pointed in the right direction will be great!
EDIT
I wanted to give some additional info as I cant seem to get the above array out of the results variable here is what I am using to process the google analytics api:
function getResults($analytics, $profileId) {
// Calls the Core Reporting API and queries for the number of sessions
// for the last seven days.
$optParams = array(
'dimensions' => 'ga:date'
);
return $analytics->data_ga->get(
'ga:' . $profileId,
'30daysAgo',
'today',
'ga:pageviews, ga:sessions',
$optParams
);
}
//$profile = $r['google_analytics'];
$profile = '69903642';
$results = getResults($analytics, $profile);
I believe the code will work that was given in the first answer but right now it is producing an empty array.
This code should work for you:
$pageViews = [];
$visits = [];
foreach($data as $key => $item) {
$pageViews[$key][$item[0]] = $item[2];
$visits[$key][$item[0]] = $item[1];
}
It will give you two separate arrays. Output:
array(
0 => array(
'20160922' => 911
)
)
array(
0 => array(
'20160922' => 2217
)
)
You can modify the code a little bit:
$pageViews = [];
$visits = [];
foreach($data as $key => $item) {
$pageViews[$item[0]] = $item[2];
$visits[$item[0]] = $item[1];
}
for output like this one:
array(
'20160922' => 2217,
......
)
I would like to filter part of a multidimensional array. I have used the array_filter function. When I print the filtered data, it shows correctly, but I can't seem to save the data back to the array.
Here is the multidimensional array (called $posted_product_details) beforehand, containing the internal array ([data]) which I would like filter:
Array
(
[column_1] => Array
(
[name] => Colour
[data] => Array
(
[0] => Blue
[1] => Green
[2] => Red
[3] => Yellow
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
[column_2] => Array
(
[name] => Pack QTY
[data] => Array
(
[0] => 3
[1] => 3
[2] => 3
[3] => 3
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
[column_3] => Array
(
[name] => Product Code
[data] => Array
(
[0] => 65030
[1] => 65029
[2] => 65028
[3] => 65031
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
[column_4] => Array
(
[name] => Barcode
[data] => Array
(
[0] => 5099570650307
[1] => 5099570650291
[2] => 5099570650284
[3] => 5099570650314
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
[column_5] => Array
(
[name] =>
[data] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
)
Here I attempt to loop through the array and filter the data:
foreach ($posted_product_details as $column => $info) {
$name = $info['name'];
$data = $info['data'];
$info['data'] = array_filter($data);
}
However, upon printing the array afterward, the array has not changed.
Pass the value by reference to modify the original array:
foreach ($posted_product_details as $column => & $info) {
$name = $info['name'];
$data = $info['data'];
$info['data'] = array_filter($data);
}
This will correctly filter the data part of your array. However, if you need to filter out deeper elements, you'll have to use a recursive function, such as this one.
Demo!
The foreach construct makes a copy of each piece of the array as you iterate over it. You have to explicitly call the original array to edit it:
$posted_product_details[$column]['data'] = array_filter($data);
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