I have an array AllUsers
as
Array AllUsers
(
[0] => Array
(
[0] => Array
(
[0] => Tim
[1] => [email protected]
)
[1] => Array
(
[0] => John
[1] => [email protected]
)
)
[1] => Array
(
[0] => Array
(
[0] => Mike
[1] => [email protected]
)
[1] => Array
(
[0] => Aron
[1] => [email protected]
)
)
)
I have another array FilteredUsers
as
Array FilteredUsers
(
[0] => Array
(
[0] => John
[1] => [email protected]
)
[1] => Array
(
[0] => Mike
[1] => [email protected]
)
[2] => Array
(
[0] => Mike
[1] => [email protected]
)
)
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] => [email protected]
)
[1] => Array
(
[0] => John
[1] => [email protected]
)
[2] => Array
(
[0] => Mike
[1] => [email protected]
)
)
[1] => Array
(
[0] => Array
(
[0] => Mike
[1] => [email protected]
)
[1] => Array
(
[0] => Aron
[1] => [email protected]
)
[2] => Array
(
[0] => John
[1] => [email protected]
)
)
[2] => Array
(
[0] => Array
(
[0] => Mike
[1] => [email protected]
)
)
)
for($i = 0; $i <= count($AllUsers), $i += 3){}
– Vlad Preda Jan 17 '13 at 15:12