开发者

How to split array in two other arrays

How do I extract the key and the value of an array into two separate arrays, with autoincrementin开发者_运维问答g integers as keys:

Ex:

Base:
Array ( [MX] => 13 ); 

Array 1:
Array ( [0] => MX ); 

Array 2:
Array ( [0] => 13 ); 

This with some neat php function.

Thanks in advance.


use array_keys() and

array_values()

Array Keys

$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

Result

Array

(
    [0] => 0
    [1] => color
)

Array Values

$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));

Result

Array
(
    [0] => XL
    [1] => gold
)


Use array_keys() and array_values().

$array1 = array_keys($base);

$array2 = array_values($base);


$array1= array_keys($base_array);
$array2= array_values($base_array);


You can use array_keys() and array_values

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜