array array_fill_keys ( array $keys , mixed $value )
引數說明:<?php $keys = array('foo', 5, 10, 'bar'); //鍵名陣列 $a = array_fill_keys($keys, 'banana'); //使用$keys陣列的值作為鍵, banana作為值來新建一個陣列 $b = array_fill_keys($keys, array('red','green','blue')); //使用$keys陣列的值作為鍵, 另一個陣列作為元素, 建立一個新的二維陣列 print_r($a); print_r($b); ?>執行以上程式的輸出結果為:
Array
(
[foo] => banana
[5] => banana
[10] => banana
[bar] => banana
)
Array
(
[foo] => Array
(
[0] => red
[1] => green
[2] => blue
)
[5] => Array
(
[0] => red
[1] => green
[2] => blue
)
[10] => Array
(
[0] => red
[1] => green
[2] => blue
)
[bar] => Array
(
[0] => red
[1] => green
[2] => blue
)
)