Instead of array_push you can just do: $yourarray[$index] = $value; If the $index already exists, it will overwrite, but you can check for that if you don't want that to happen.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
If you loop through your values, why not just do $newarray[] = $value; (just like array_push). I really don't see why you'd get key duplicates, as it just renumbers the new array from zero upwards (based on your sample).
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
You are overwriting your data by using two identical variables
foreach($fileIN as $fileIN) { ... }
This should be:
foreach($fileIN as $value) { array_push($value, "X"); }
Then I guess the array_merge will work just fine.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
I think this should work:
$fileIN = array_chunk($files, 3, true);
$fileOUT = array ();
foreach ($fileIN as $chunk)
{
foreach ($chunk as $value)
{
$fileOUT[] = $value;
}
$fileOUT[] = "X";
}
print_r($fileOUT);
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875