i have a PHP array as follow :
$array = array("one" => "is one" , "two" => "is two" , "three" => "is three", "four" => "is four" , "five" => "is five" , "six" => "is six" , "seven" => "is seven" , "eight" => "is eight" , "nine" => "is nine" , "ten" => "is ten");
After partitioning this array into two groups that is 5 elements, using following method:
function partition(Array $list, $p) {
$listlen = count($list);
$partlen = floor($listlen / $p);
$partrem = $listlen % $p;
$partition = array();
$mark = 0;
for($px = 0; $px < $p; $px ++) {
$incr = ($px < $partrem) ? $partlen + 1 : $partlen;
$partition[$px] = array_slice($list, $mark, $incr);
$mark += $incr;
}
return $partition;
}
$partitioned = partition($array , 2);
Now to use this partitioned array i use the following code :
$totalArrays = count($partitioned);
for($pb=0; $pb < $totalArrays; $pb++){
print_r($partitioned[$pb]);
}
The above print_r($partitioned[$pb]);
outputs 2 arrays.
This displays the contents of both arrays as keys and values, what i actually wanted to achieve is that , i would like to save elements of first array into one file named "First.txt" and "Second.txt" for the second, the names doesn't matters they can be numbered but what matters is the partitions, forexample if there are 10 partitions each partition will save its element into its own file.
I have had some solutions but they ain't working as expected so i am here to request for your solutions.
Thank you.