The array is divided into two parts

Source: Internet
Author: User
The array is divided into two sections
A one-dimensional array, note that the key name is irregular and non-numeric:
$arr =array (' WC ' =>12, ' WSSC ' =>123, ' WAC ' =>142 ', ' =>124 ', ' WAC ' =>012, ' wsbsc ' =>012c3, ' WAC ' = 014d2 ', W3ec ' =>0124);
It is now divided into two parts, namely:
$arr 1=array (' WC ' =>12, ' WSSC ' =>123, ' WAC ' =>142 ', ' =>124 ');
And
$arr 2=array (' WAC ' =>012, ' wsbsc ' =>012c3, ' WAC ' =>014d2 ', W3ec ' =>0124 ');

To find this algorithm

------Solution--------------------
You didn't specify any division rules--

Array_chunk ()
Or
Array_slice ()
------Solution--------------------
The condition of the original split is obviously, to determine whether the first character is 0.
Unfortunately, your problem is wrong, because the association key WAC is duplicated. So the array $arr only 7 items
An array of 7 items split into a total of 8 items, because the condition is not sufficient, so no solution!


You're not challenging our IQ, are you?
------Solution--------------------
Regardless of your array there are no errors, but this method should be feasible (elements of an even number, or odd number, the number of a few):
Asort ($arr);
Then intercept the front to OK. For interception, you can use a function, or you can assign a value to another array

  • 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.