tonelm54
asked on
Array collection of files
I'm trying to make an array of files which will hold a list of files, per remittance, so in my example I have 2 remitances both of 2 pages, so in simple terms Im trying to set my array up as:-
The code runs a lot more lines to get this information, so I cant use, but will get what I want.
So, my issue is 3 part:-
1 - I dont understand why I get the error - E_NOTICE : type 8 -- Undefined offset: 0 -- at line 4
2 - I dont understand the Warnings - E_WARNING : type 2 -- Illegal string offset 'files' -- at line 7 and E_WARNING : type 2 -- Illegal string offset 'files' -- at line 8
3 - The returned array after a print_r, isnt what I would have expected, where did the "P" come from? :-S:-
Any ideas what Im doing wrong in what looks like a simple task :-S
Thank you
$remitanceCollection = array();
array_push($remitanceCollection, $remitanceCollection[0]["files"],"Page0");
array_push($remitanceCollection, $remitanceCollection[0]["files"],"Page1");
array_push($remitanceCollection, $remitanceCollection[1]["files"],"Page2");
array_push($remitanceCollection, $remitanceCollection[1]["files"],"Page3");
The code runs a lot more lines to get this information, so I cant use, but will get what I want.
$remitanceCollection = array("0"=>array("Files"=>array("Page1","Page2")),"1"=>array("Files"=>array("Page3","Page4")));
So, my issue is 3 part:-
1 - I dont understand why I get the error - E_NOTICE : type 8 -- Undefined offset: 0 -- at line 4
2 - I dont understand the Warnings - E_WARNING : type 2 -- Illegal string offset 'files' -- at line 7 and E_WARNING : type 2 -- Illegal string offset 'files' -- at line 8
3 - The returned array after a print_r, isnt what I would have expected, where did the "P" come from? :-S:-
Array ( [0] => [1] => Page0 [2] => [3] => Page1 [4] => P [5] => Page2 [6] => P [7] => Page3 )
Any ideas what Im doing wrong in what looks like a simple task :-S
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good morning Marco Gasi,
I have actually closed this, and opened a new ticket under 28929112, as I still cant get this working :-S
The problem with your solution is I cannot add the pages to the array in one line as in:-
I need to add them in sepertatly, like:-
Because Im reading each page and then assigning the pages to the correct remitance file, so at the end I will have an array of remitances, each with an array of what pages they should contain. Then I can patch them together.
Thank you
I have actually closed this, and opened a new ticket under 28929112, as I still cant get this working :-S
The problem with your solution is I cannot add the pages to the array in one line as in:-
array_push($remitanceCollection, array("File01"=>array("Page0", "Page1")));
I need to add them in sepertatly, like:-
array_push($remitanceCollection, array("File01"=>array("Page0")));
array_push($remitanceCollection, array("File01"=>array("Page1")));
Because Im reading each page and then assigning the pages to the correct remitance file, so at the end I will have an array of remitances, each with an array of what pages they should contain. Then I can patch them together.
Thank you
I think you should rethink your array structure depending on how you retrieve the file list and the pages for each file...
Anyway, in order to get an array similar the one you have shown above you should write something like this
Open in new window
Actually, I would need to see more code and how you get files and pages to give you a better help, but this should give you an idea. Probably the array $remitanceCollection should be filled within a loop through another array which stores files and the number of pages per file...