简体   繁体   中英

Native php function to turn single dimensional array into two dimensional

I want to turn plain array into two dimensional array. I can do it with a code below but is there native PHP function to handle it. I went through the manual and wen but didn't see anything.

Thanks

$array = array('a', 'b');

Should be converted into:

$array = array('a'=>'a', 'b'=>'b');

I don't want to use this if there is a simple function:

foreach($array as &$value)
{
    $new[$value] = $value;
}

您可以使用array_combine() ,它将(一个array_combine()键数组和值数组组合到一个数组中。

$array = array_combine($array, $array);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM