How to get values in an array with many arrays in php? - php

I am confused with this list of array. I have a text file that contains the values that I will need to insert to the database. I have exploded it so that I can get those separated values.
REP 1020001,3,140822,140822;0111,260.00,23,34,3,54,1,2,4,5,12,23,46;0214,22.00,32,4,11,25,4,12,23,5,2,2,44;0313,25.00,5,52,12,45,12,5,6,7,12,3,33;
My code is just like this:
$read = FileRead($tmp);
$perline = explode(";",$read);
for($j=0; $j<count($perline); $j++)
{
$percomma = explode(",", $perline[$j]);
print_r ($percomma);
}
And the result is this:
Array ( [0] => 1020001 [1] => 3 [2] => 140822 [3] => 140822 ) Array ( [0] => 0111 [1] => 260.00 [2] => 23 [3] => 34 [4] => 3 [5] => 54 [6] => 1 [7] => 2 [8] => 4 [9] => 5 [10] => 12 [11] => 23 [12] => 46 ) Array ( [0] => 0214 [1] => 22.00 [2] => 32 [3] => 4 [4] => 11 [5] => 25 [6] => 4 [7] => 12 [8] => 23 [9] => 5 [10] => 2 [11] => 2 [12] => 44 ) Array ( [0] => 0313 [1] => 25.00 [2] => 5 [3] => 52 [4] => 12 [5] => 45 [6] => 12 [7] => 5 [8] => 6 [9] => 7 [10] => 12 [11] => 3 [12] => 33 ) Array ( [0] => )
What should I do to get the value from the 2nd array to the 4th array? Should I put it inside another array to make it multidimensional? Or there are other ways to solve this?
EDIT
My question is how will I be able to get the values from the print_r($percomma) when there are a lot of arrays in the result. The result array is up there that says And the result is this
EDIT 2
As making the array to be multidimensional I get this as a result:
Array ( [0] => Array ( [0] => 0111 [1] => 260.00 [2] => 23 [3] => 34 [4] => 3 [5] => 54 [6] => 1 [7] => 2 [8] => 4 [9] => 5 [10] => 12 [11] => 23 [12] => 46 ) ) Array ( [0] => Array ( [0] => 0214 [1] => 22.00 [2] => 32 [3] => 4 [4] => 11 [5] => 25 [6] => 4 [7] => 12 [8] => 23 [9] => 5 [10] => 2 [11] => 2 [12] => 44 ) ) Array ( [0] => Array ( [0] => 0313 [1] => 25.00 [2] => 5 [3] => 52 [4] => 12 [5] => 45 [6] => 12 [7] => 5 [8] => 6 [9] => 7 [10] => 12 [11] => 3 [12] => 33 ) ) Array ( [0] => Array ( [0] => ) )
It shows that they're all individual arrays. My code is this:
$read = FileRead($tmp);
$perline = explode(";",$read);
for($j=0; $j<count($perline); $j++)
{
$percomma = explode(",", $perline[$j]);
$entries = array($percomma);
print_r ($entries);
}
EDIT 3
From subas_poudel's answer I get this result:
Array
(
)
Array
(
[0] => Array
(
[0] => 0111
[1] => 260.00
[2] => 23
[3] => 34
[4] => 3
[5] => 54
[6] => 1
[7] => 2
[8] => 4
[9] => 5
[10] => 12
[11] => 23
[12] => 46
)
)
Array
(
[0] => Array
(
[0] => 0111
[1] => 260.00
[2] => 23
[3] => 34
[4] => 3
[5] => 54
[6] => 1
[7] => 2
[8] => 4
[9] => 5
[10] => 12
[11] => 23
[12] => 46
)
[1] => Array
(
[0] => 0214
[1] => 22.00
[2] => 32
[3] => 4
[4] => 11
[5] => 25
[6] => 4
[7] => 12
[8] => 23
[9] => 5
[10] => 2
[11] => 2
[12] => 44
)
)
Array
(
[0] => Array
(
[0] => 0111
[1] => 260.00
[2] => 23
[3] => 34
[4] => 3
[5] => 54
[6] => 1
[7] => 2
[8] => 4
[9] => 5
[10] => 12
[11] => 23
[12] => 46
)
[1] => Array
(
[0] => 0214
[1] => 22.00
[2] => 32
[3] => 4
[4] => 11
[5] => 25
[6] => 4
[7] => 12
[8] => 23
[9] => 5
[10] => 2
[11] => 2
[12] => 44
)
[2] => Array
(
[0] => 0313
[1] => 25.00
[2] => 5
[3] => 52
[4] => 12
[5] => 45
[6] => 12
[7] => 5
[8] => 6
[9] => 7
[10] => 12
[11] => 3
[12] => 33
)
)
Array
(
[0] => Array
(
[0] => 0111
[1] => 260.00
[2] => 23
[3] => 34
[4] => 3
[5] => 54
[6] => 1
[7] => 2
[8] => 4
[9] => 5
[10] => 12
[11] => 23
[12] => 46
)
[1] => Array
(
[0] => 0214
[1] => 22.00
[2] => 32
[3] => 4
[4] => 11
[5] => 25
[6] => 4
[7] => 12
[8] => 23
[9] => 5
[10] => 2
[11] => 2
[12] => 44
)
[2] => Array
(
[0] => 0313
[1] => 25.00
[2] => 5
[3] => 52
[4] => 12
[5] => 45
[6] => 12
[7] => 5
[8] => 6
[9] => 7
[10] => 12
[11] => 3
[12] => 33
)
)
The last set of array is what I needed but how can I get those values?
EDIT 4
With my simple mistake I put the array_slice inside my for loop that's why I get too many arrays. Now this is the result of #subas_poudel's answer.
Array
(
[0] => Array
(
[0] => 0111
[1] => 260.00
[2] => 23
[3] => 34
[4] => 3
[5] => 54
[6] => 1
[7] => 2
[8] => 4
[9] => 5
[10] => 12
[11] => 23
[12] => 46
)
[1] => Array
(
[0] => 0214
[1] => 22.00
[2] => 32
[3] => 4
[4] => 11
[5] => 25
[6] => 4
[7] => 12
[8] => 23
[9] => 5
[10] => 2
[11] => 2
[12] => 44
)
[2] => Array
(
[0] => 0313
[1] => 25.00
[2] => 5
[3] => 52
[4] => 12
[5] => 45
[6] => 12
[7] => 5
[8] => 6
[9] => 7
[10] => 12
[11] => 3
[12] => 33
)
)

you can use multidimensional array to hold all the value. then you can get all the array you want by either $percomma[index you want] or using array_slice.
$read = FileRead($tmp);
$perline = explode(";",$read);
for($j=0; $j<count($perline); $j++)
{
$percomma[] = explode(",", $perline[$j]);
}
echo '<pre>'.print_r (array_slice($percomma,1,3),true).'</pre>';

$array = array
(
array("bla",22,18),
array("blaa",15,13),
array("blaaa",5,2),
array("blaaaa",17,15)
);
for ($row = 0; $row < 4; $row++) {
echo "<p><b>Row number $row</b></p>";
echo "<ul>";
for ($col = 0; $col < 3; $col++) {
echo "<li>".$array[$row][$col]."</li>";
}
echo "</ul>";
}

I'm going to copy/edit your original code posting, to show what I was talking about in my comment.
$read = FileRead($tmp);
$perline = explode(";",$read);
$percomma = array(); //new array-declaration line
for($j=0; $j<count($perline); $j++)
{ $percomma[j] = explode(",", $perline[$j]);
print_r ($percomma[j]);
}
Your first "And the result is" line is a printed sequence of arrays, and would be unchanged by implementing the above tweaks to your code. However, because the values in the $percomma variable are no longer overwritten in each loop that obtains an array from the explode() function, you may now, at any point after the above code, do something like:
print_r($percomma[1]); //re-print 2nd array, or
$ary_el = $percomma[2][1]; //get 2nd element of 3rd array (22.00) into a variable.

Related

Convert csv into array but split array by same date and execute a function on each array

CSV:
0021044-1;16/02/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021044-2;16/02/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021064-1;21/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021064-1;21/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021067-1;19/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021087-1;14/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021087-2;14/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
I'm splitting the array with the following PHP code:
$csv = array_map(function ($v) {
return str_getcsv($v, ";");
}, file($file);
// Where file stands for the csv file being loaded.
Which gives me the following array
Array
(
[0] => Array
(
[0] => 0021044-1
[1] => 16/02/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[1] => Array
(
[0] => 0021044-2
[1] => 16/02/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[2] => Array
(
[0] => 0021064-1
[1] => 21/01/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[3] => Array
(
[0] => 0021064-1
[1] => 21/01/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[4] => Array
(
[0] => 0021067-1
[1] => 19/01/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[5] => Array
(
[0] => 0021087-1
[1] => 14/01/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[6] => Array
(
[0] => 0021087-2
[1] => 14/01/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
)
However, what I want to do is get the lines with the same date and perform a function on them
e.g;
Put the values
0021044-1;16/02/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021044-2;16/02/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
Then do a function on this array
0021064-1;21/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021064-1;21/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
Then do same function on this array
0021067-1;19/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
Then do same function on this array
0021087-1;14/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
0021087-2;14/01/2022;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15
Then do same function on this array
So in short, the function should be applied to a newly generated array out of this one, array as follows:
$new_array = Array
(
[0] => Array
(
[0] => 0021044-1
[1] => 16/02/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
[1] => Array
(
[0] => 0021044-2
[1] => 16/02/2022
[2] => 1
[3] => 2
[4] => 3
[5] => 4
[6] => 5
[7] => 6
[8] => 7
[9] => 8
[10] => 9
[11] => 10
[12] => 11
[13] => 12
[14] => 13
[15] => 14
[16] => 15
)
do the function csv2xml($new_array);
And then the second find of the other date etc...
do the function again etc..
All the sub arrays created on their appropriate date will then go to a function which I have covered already in a function called csv2xml($arr)
Though, I'm not succeeding in splitting the array into array's per date.
Can someone guide me in the correct direction?
I think it's a lot of for, while and loops nested in eachother but my brain is currently melting on this..
If the rows will always have the 2 dates following each other you can simply walk through the file calling your function on every other line, with a little check for those dates where only one line exists
I made up a little function to mimic your call that just prints the 2 dates to make sure it works.
function call_function($a1, $a2)
{
echo sprintf( "The 2 dates are %s and %s\n", $a1[1] , $a2[1]);
}
$f = fopen('tst.csv', 'r');
$last_date = NULL;
$last_line = NULL;
while ( ($line = fgetcsv($f, 1024, ';')) !== FALSE){
if ( $line[1] == $last_date ){
// we got the second of a set of dates so call your function
call_function($last_line, $line);
} else {
$last_date = $line[1];
$last_line = $line;
}
}
RESULTS
The 2 dates are 16/02/2022 and 16/02/2022
The 2 dates are 21/01/2022 and 21/01/2022
The 2 dates are 14/01/2022 and 14/01/2022

convert the array to the correct form

After converting the file
$rows = array_map('trim', file($lines1));
foreach ($rows as $key => $value) {
$params = array_map('trim', explode(';', $value));
}
an array of the following type is obtained, which is contained in a variable:
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => i need this [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 )
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => i need this [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 [14] => 14 )
etc...
how can you combine these arrays and put the values with the key = 3 into separate variables.
View:
Array ( [0] => i need this [1] => i need this and etc...
$range = range(1, 100);
$result = array_combine($range, $range);
check array_combine

Php array remove duplicate and put toghether in another array

I have this php array:
Array
(
[0] => Array
(
[0] => 2505
[1] => Lima
[2] => Daniels
[3] => 0996995904
[4] =>
[5] => 755971
[6] => 1454284800
[7] => Cat. A (Moto)
[8] => 0
[9] => 1
[10] => 1
)
[1] => Array
(
[0] => 2505
[1] => Lima
[2] => Daniels
[3] => 0996995904
[4] =>
[5] => 755971
[6] => 1454284800
[7] => Cat. A (Moto)
[8] => 1
[9] => 0
[10] => 0
)
[2] => Array
(
[0] => 2505
[1] => Lima
[2] => Daniels
[3] => 0996995904
[4] =>
[5] => 755971
[6] => 1454284800
[7] => Cat. A (Moto)
[8] => 0
[9] => 0
[10] => 0
)
[3] => Array
(
[0] => 2525
[1] => Lomarca
[2] => Miro
[3] => 0099778877
[4] =>
[5] => 768131
[6] => 1454976000
[7] => Cat. A (Moto)
[8] => 1
[9] => 0
[10] => 0
)
[4] => Array
(
[0] => 2525
[1] => Lomarca
[2] => Miro
[3] => 0099778877
[4] =>
[5] => 768131
[6] => 1454976000
[7] => Cat. A (Moto)
[8] => 0
[9] => 1
[10] => 0
)
)
I want i new array:
1) if element [0] exists in the array I want to control elements 8, 9 and 10 and if one of this is 1 I want to have 1 in the final array, but I don't want to have the same array 2 times (the index [0] is the key).
My final array shound be:
Array
(
[0] => Array
(
[0] => 2505
[1] => Lima
[2] => Daniels
[3] => 0996995904
[4] =>
[5] => 755971
[6] => 1454284800
[7] => Cat. A (Moto)
[8] => 1
[9] => 1
[10] => 1
)
[3] => Array
(
[0] => 2525
[1] => Lomarca
[2] => Miro
[3] => 0099778877
[4] =>
[5] => 768131
[6] => 1454976000
[7] => Cat. A (Moto)
[8] => 1
[9] => 1
[10] => 0
)
)
I have only one time the index 2505 and 2505 and index 8 and 9 and 10 are 1 for the 2505 and the index 8 and 9 are 1 for the 2525.
this does the job: (assuming that your first array is $arrays and your desired result is $result)
$result = array();
foreach($arrays as $array)
{
if(!isset($result[$array[0]]))
{
$result[$array[0]] = $array;
}
else
{
$result[$array[0]][8] = $array[8] == 1 ? 1 : $result[$array[0]][8];
$result[$array[0]][9] = $array[9] == 1 ? 1 : $result[$array[0]][9];
$result[$array[0]][10] = $array[10] == 1 ? 1 : $result[$array[0]][10];
}
}
but wherever you get your data from, e.g. a database, I would use element[0] as the key, so you don't get multiple entries in $arrays. Another option would be to create a class which holds your data...

multidimensional array sort based on database column value compare

I have following multidimensional array
Array
(
[1] => 22
[2] => 12
[3] => Array
(
[0] => 4
[1] => 21
)
[5] => Array
(
[0] => 9
[1] => 3
)
[7] => 7
[8] => 6
[9] => 1
[10] => 2
[11] => 10
[12] => 0
[13] => 23
[14] => 18
[15] => 16
[16] => 19
[17] => 15
[18] => 5
[19] => 8
[20] => 11
[21] => 13
[22] => 17
[23] => 14
[24] => 20
)
I want to sort morethan one value below array from main array.
Array
(
[3] => Array
(
[0] => 4
[1] => 21
)
[5] => Array
(
[0] => 9
[1] => 3
)
)
Each key value compare with database column and sort an array. If not found value then array keep as it is.
For example:
The below key value is 21 have in database column then am expected results as,
[3] => Array
(
[0] => 21
[1] => 4
)
look as next array, the next array key value not found in the database then expected results as it is,
[5] => Array
(
[0] => 9
[1] => 3
)
The final output look for,
Array
(
[1] => 22
[2] => 12
[3] => Array
(
[0] => 21
[1] => 4
)
[5] => Array
(
[0] => 9
[1] => 3
)
[7] => 7
[8] => 6
[9] => 1
[10] => 2
[11] => 10
[12] => 0
[13] => 23
[14] => 18
[15] => 16
[16] => 19
[17] => 15
[18] => 5
[19] => 8
[20] => 11
[21] => 13
[22] => 17
[23] => 14
[24] => 20
)
Could you please help me
Check this.
$dump_array=Array('1' => 2,'2' => 12,'3' => Array
('0' => 8,'1' => 21 ),
'5' => Array ('0' => 9,'1' => 3),
'7' => 7,
'8' => 64,
'9' => 15,
'10' => 22,
);
echo "<pre> Soure :"; print_r($dump_array);echo "</pre>";
sort($dump_array);
$result_array=array();
$array_unlist=array();
foreach($dump_array as $key=>$value){
if(is_array($value)){
sort($value);
array_push($array_unlist,$value);
}
else {array_push($result_array,$value);}
}
foreach($result_array as $index=>$val){
foreach($array_unlist as $key=>$digit){
if($val<$digit[0])
{
$res=$index.".5";
$result_array[$res]=$digit;
}
}
}
ksort($result_array);
echo "<pre> Result :"; print_r(array_values($result_array));echo "</pre>";
output:
Soure :Array
(
[1] => 2
[2] => 12
[3] => Array
(
[0] => 8
[1] => 21
)
[5] => Array
(
[0] => 9
[1] => 3
)
[7] => 7
[8] => 64
[9] => 15
[10] => 22
)
Result :Array
(
[0] => 2
[1] => Array
(
[0] => 3
[1] => 9
)
[2] => 7
[3] => Array
(
[0] => 8
[1] => 21
)
[4] => 12
[5] => 15
[6] => 22
[7] => 64
)
try this
foreach($array as $k => $v){
if(is_array($v)){
rsort($array[$k]);
}
}
print_r($array);

php calendar and multidimensional arrays

I have an array of calendar dates, and an multidimensional array of reports where the key to the reports is the date
Array of calendar dates structure
Array
(
[1] => 2014-05-01
[2] => 2014-05-02
[3] => 2014-05-03
[4] => 2014-05-04
[5] => 2014-05-05
[6] => 2014-05-06
[7] => 2014-05-07
[8] => 2014-05-08
[9] => 2014-05-09
[10] => 2014-05-10
[11] => 2014-05-11
[12] => 2014-05-12
[13] => 2014-05-13
[14] => 2014-05-14
[15] => 2014-05-15
[16] => 2014-05-16
[17] => 2014-05-17
[18] => 2014-05-18
[19] => 2014-05-19
[20] => 2014-05-20
[21] => 2014-05-21
[22] => 2014-05-22
[23] => 2014-05-23
[24] => 2014-05-24
[25] => 2014-05-25
[26] => 2014-05-26
[27] => 2014-05-27
[28] => 2014-05-28
[29] => 2014-05-29
[30] => 2014-05-30
[31] => 2014-05-31
)
And my Array of reports structure
Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
)
Now i want to loop through the calendar and for every value in the calendar array (the date) that matches the key of the report array (eg the date), i want to attach the reports to calendar value and use the value calendar as a key to the reports other wise i want to add a string saying no reports done.
heres how i though i might go about
foreach ($calendar as $cal)
{
foreach ($report as $key => $rdate)
{
if ($key == $cal)
{
$calendar[][$cal] = $rdate;
}
}
}
this however just adds them to the end of the calendar array and not where the calendar value and report key match.
Like so
Array
(
[1] => 2014-05-01
[2] => 2014-05-02
[3] => 2014-05-03
[4] => 2014-05-04
[5] => 2014-05-05
[6] => 2014-05-06
[7] => 2014-05-07
[8] => 2014-05-08
[9] => 2014-05-09
[10] => 2014-05-10
[11] => 2014-05-11
[12] => 2014-05-12
[13] => 2014-05-13
[14] => 2014-05-14
[15] => 2014-05-15
[16] => 2014-05-16
[17] => 2014-05-17
[18] => 2014-05-18
[19] => 2014-05-19
[20] => 2014-05-20
[21] => 2014-05-21
[22] => 2014-05-22
[23] => 2014-05-23
[24] => 2014-05-24
[25] => 2014-05-25
[26] => 2014-05-26
[27] => 2014-05-27
[28] => 2014-05-28
[29] => 2014-05-29
[30] => 2014-05-30
[31] => 2014-05-31
[32] => Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
)
[33] => Array
(
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
)
[34] => Array
(
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
)
[35] => Array
(
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
)
[36] => Array
(
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
)
[37] => Array
(
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
)
[38] => Array
(
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
)
[39] => Array
(
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
)
[40] => Array
(
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
)
)
instead of this i would like this
Array (
[1] => 2014-05-01 => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
...........
)
I think where i have been bashing my head against a wall i cant see the woods from the trees.
Any help would be grand or guidence would be grand.
regards Mike
So by writing this out i must of figured it out so it actually helped me just by forming the question, this is what i changed
foreach ($dates_month_with_reports as $cal)
{
foreach ($reportdates as $key => $rdate)
{
if ($key == $cal)
{
//took away the extra array
$dates_month_with_reports[$cal] = $rdate;
}
}
}
and in the calendar array i added the date to the key aswell which now gives me this
Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
[2014-05-02] => 2014-05-02
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
[2014-05-04] => 2014-05-04
[2014-05-05] => 2014-05-05
[2014-05-06] => 2014-05-06
[2014-05-07] => 2014-05-07
[2014-05-08] => 2014-05-08
[2014-05-09] => 2014-05-09
[2014-05-10] => 2014-05-10
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
[2014-05-12] => 2014-05-12
[2014-05-13] => 2014-05-13
[2014-05-14] => 2014-05-14
[2014-05-15] => 2014-05-15
[2014-05-16] => 2014-05-16
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
[2014-05-21] => 2014-05-21
[2014-05-22] => 2014-05-22
[2014-05-23] => 2014-05-23
[2014-05-24] => 2014-05-24
[2014-05-25] => 2014-05-25
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
[2014-05-28] => 2014-05-28
[2014-05-29] => 2014-05-29
[2014-05-30] => 2014-05-30
[2014-05-31] => 2014-05-31
)
I appologize for wasting your time i didnt mean to, but after i wrote the question a figured it out.
$calendar1 = array();
foreach ($calendar as $cal)
{
foreach ($report as $key => $rdate)
{
if ($key == $cal)
{
$calendar1[][$cal] = $rdate;
}
}
}

Categories