PHP array of processing help, expert help, thank you.
This post was last edited by a858070363 on 2015-05-02 16:29:12
1. The data submitted by the form is: value 1, value 2, value 3, value 4, value 5, value 6 ...
2, I use the explode function to process the form submission, converted to an array
my question now is:
Remove one value per 3 and turn the last array into the format at the beginning, such as: value 1, value 2, value 4, value 5
How is code implemented?
Toss for two days, really do not, ask for help. Thank.
------to solve the idea----------------------
$data = ' value 1, value 2, value 3, value 4, value 5, value 6 ';
$DATAARR = Explode (', ', $data);
foreach ($dataArr as $key = = $value) {
if ($key%3 = = 2) {
Unset ($DATAARR [$key]);
}
}
$res = Implode (', ', $DATAARR);
Echo $res;
It would be nice to take apart the traversal and merge
------to solve the idea----------------------
This post was last edited by xuzuning on 2015-05-02 17:46:32
$n = 5; Each of 5
$s = ' value 1, value 2, value 3, value 4, value 5, value 6, value 7, value 8, value 9, value 10, value 11 ';
$a = explode (', ', $s);
foreach ($a as $k = $v) if ($k% $n = = $n-1) unset ($a [$k]);
$res = Join (', ', $a);
Echo $res;
Value 1, value 2, value 3, value 4, value 6, value 7, value 8, value 9, value 11
But the meaning of every few and each is different. Adjust yourself.
------to solve the idea----------------------
$key%3 = = 2 Can you read this?
When writing 3 $n, 2 can write $n-1?