I have an array AllUsers as
Array AllUsers
(
[0] => Array
(
[0] => Array
(
[0] => Tim
[1] => tim@gmail.com
)
[1] => Array
(
[0] => John
[1] => john@gmail.com
)
)
[1] => Array
(
[0] => Array
(
[0] => Mike
[1] => mike@gmail.com
)
[1] => Array
(
[0] => Aron
[1] => aron@gmail.com
)
)
)
I have another array FilteredUsers as
Array FilteredUsers
(
[0] => Array
(
[0] => John
[1] => john@yahoo.com
)
[1] => Array
(
[0] => Mike
[1] => mike@yahoo.com
)
[2] => Array
(
[0] => Mike
[1] => mike@outlook.com
)
)
Now what I want is to add every element of FilteredUsers[] in AllUsers[] such that –
FilteredUsers[0]should get added to BatchAllUsers[1]because BatchAllUsers[0]already has array with element name John in it- Similarly
FilteredUsers[1]should get added to BatchAllUsers[0] - Any Batch (like
AllUsers[0],AllUsers[1]) can’t have more than 3 elements. If all Batches are full, then a new batch shall be created but every element inFilteredUsers[]should be accommodated in some Batch.
So the updated AllUsers array should be something like this –
Array AllUsers
(
[0] => Array
(
[0] => Array
(
[0] => Tim
[1] => tim@gmail.com
)
[1] => Array
(
[0] => John
[1] => john@gmail.com
)
[2] => Array
(
[0] => Mike
[1] => mike@yahoo.com
)
)
[1] => Array
(
[0] => Array
(
[0] => Mike
[1] => mike@gmail.com
)
[1] => Array
(
[0] => Aron
[1] => aron@gmail.com
)
[2] => Array
(
[0] => John
[1] => john@yahoo.com
)
)
[2] => Array
(
[0] => Array
(
[0] => Mike
[1] => mike@outlook.com
)
)
)
Here is the working code:
I have created a code pastebin also for you at: http://codepad.org/iyZUpYxc
Note: You have missed the array
(
[0] => John
[1] => john@yahoo.com
) in your Output above.
But my code outputs that also correctly.
Thanks