How can I use php to split an array into two new arrays based on conditions and save the newly created array as an English key? (Examples already exist in the question)

Source: Internet
Author: User
{Code ...} question 1: divide the first index into a $ int array of 0, 1, and 2, and divide the English keys a, B, and c into a $ string array. I don't know how to deal with the distinction between 0, 1, 2 and English keys, because they are all string types? (Resolved) Question 2: {code...} after var_dump...
$array = array('0'=>'3','1','2','a'=>'a','b'=>'b','c'=>'c')

Question 1:
Divide the first index into a $ int array of 0, 1, 2, and the English keys a, B, and c into a $ string array.
I don't know how to deal with the distinction between 0, 1, 2 and English keys, because they are all string types? (Resolved)

Question 2:

First array: array (size = 3) 0 => string '3' (length = 1) 1 => string '1' (length = 1) 2 => string '2' (length = 1) second array: array (size = 3) 0 => array (size = 1) 'A' => string 'A' (length = 1) 1 => array (size = 1) 'B' => string 'B' (length = 1) 2 => array (size = 1) 'C' => string 'C' (length = 1)

After var_dump, I used array_push in the second array, but I want the index to be indexed in English instead of numbers,
As follows:

array (size=3)  'a' => string '3' (length=1)  'b' => string '1' (length=1)  'c' => string '2' (length=1)

Reply content:
$array = array('0'=>'3','1','2','a'=>'a','b'=>'b','c'=>'c')

Question 1:
Divide the first index into a $ int array of 0, 1, 2, and the English keys a, B, and c into a $ string array.
I don't know how to deal with the distinction between 0, 1, 2 and English keys, because they are all string types? (Resolved)

Question 2:

First array: array (size = 3) 0 => string '3' (length = 1) 1 => string '1' (length = 1) 2 => string '2' (length = 1) second array: array (size = 3) 0 => array (size = 1) 'A' => string 'A' (length = 1) 1 => array (size = 1) 'B' => string 'B' (length = 1) 2 => array (size = 1) 'C' => string 'C' (length = 1)

After var_dump, I used array_push in the second array, but I want the index to be indexed in English instead of numbers,
As follows:

array (size=3)  'a' => string '3' (length=1)  'b' => string '1' (length=1)  'c' => string '2' (length=1)

is_numeric()

$arr1 = $arr2 = [];$arr = array('0'=>'3','1','2','a'=>'a','b'=>'b','c'=>'c');foreach ($arr as $key=>$value) {    if (is_numeric($key)) {        $arr1[$key] = $value;    } else {        $arr2[$key] = $value;    }}

$aaa = array(1=>'aa','2'=>'gg','cc'=>'dd');        foreach ($aaa as $key => $value) {            if (is_numeric($key)) {                echo "1".'
'; }elseif (is_string($key)) { echo "string"; } } die();

Run the code-breaking test on the previous section to test whether '1' or 'ccsdad' is 'ccsdad', which is '1' or '1'. then you can judge the two new arrays in the group.

This is the result

11string

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.