开发者

PHP arrays setting to false

How do I make it so every array is set to false .. I don't want to do it like this:

$a = array('clue1' => 'false', 'clue2' => 'false', 'clue3' => 'false');

because that will take long time. Is there easie开发者_JAVA百科r way?


http://www.php.net/manual/en/function.array-fill.php array_fill may be of use.


I think he is looking for array_fill_keys

$keys = array("clue1", "clue2", "clue3", "clue4");
$a = array_fill_keys($keys, "false");
print_r($a);

Of course you could use a for statement to setup the clue part too.

for ($x=1; $x < 5; $x++) {
    $keys[] = "clue".$x;
}
//$keys = array("clue1", "clue2", "clue3", "clue4");
$a = array_fill_keys($keys, "false");
print_r($a);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜