PHP array processing, expert help, thanks

Source: Internet
Author: User
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?
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.