在 PHP 7 中,您现在可以定义数组。
考虑以下代码
<?php
define( "EXPLENATIVES", [1 => "Foo Bar", 2 => "Fehw Bahr", 3 => "Foo Bahr", 4 => "Fooh Bar", 5 => "Fooh Bhar", 6 => "Foo Barr", 7 => "Foogh Bar", 8 => "Fehw Barr", 9 => "Fu bar", 10 => "Foo Bahr", 11 => "Phoo Bar", 12 => "Foo Bawr", 13 => "Phooh Baughr", 14 => "Foogan Bargan", 15 => "Foo Bahre", 16 => "Fu Bahar", 17 => "Fugh Bar", 18 => "Phou Baughr"]);
define("NAVBTNS", [EXPLENATIVES, "Nouns", "Verbs", "Adjectives"]);
function construct_navbar_buttons(){
$btns = '<ul class="nav navbar-nav">';
foreach(NAVBTNS as $button => $btn){
if(is_array($btn)){
$btns .= '<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="?id='.$btn.'">
<i class="glyphicon glyphicon-user"></i> You Dare Say? <i class="glyphicon glyphicon-collapse-down"></i>
</a>
<ul class="dropdown-menu dropdown-user">';
foreach(EXPLENATIVES as $key => $button){
$btns .= '<li><a href="#">'.$button.'</a></li>';
}
$btns .= '</ul>';
}else{
$btns .= '<li><a href="#">'.$btn.'</a></li>';
}
}
$btns .= '</ul>';
return $btns;
}
我喜欢这个 新 实现!
?>