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:-
	$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");

Open in new window


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")));

Open in new window


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
tonelm54Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tonelm54Author Commented:
Ok, dont shoot the spanner, on closer looks I realise Im a muppet!!!!!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Marco GasiFreelancerCommented:
array_push() accept as first parameter an array and as second parameters typically a string or another array. In your code you're passing an elment of the array itself ($remitanceCollection[0]["files"] - and this just doesn't make sense to me) and then a string ("Page0"). In addition, you're trying to create an array which has always the same index "Files" and this is not allowed: using always the same index the last inserted value will overwrite the previous one.
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
$remitanceCollection = array();
	array_push($remitanceCollection, array("File01"=>array("Page0", "Page1")));
	array_push($remitanceCollection, array("File02"=>array("Page2", "Page3")));

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...
tonelm54Author Commented:
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:-
array_push($remitanceCollection, array("File01"=>array("Page0", "Page1")));

Open in new window


I need to add them in sepertatly, like:-
array_push($remitanceCollection, array("File01"=>array("Page0")));
array_push($remitanceCollection, array("File01"=>array("Page1")));

Open in new window


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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.