我想设置一组变量,然后循环将它们添加到一个数组中,并将键设置为变量名,如下所示。
我只是不确定你是如何创建循环的。
// create an array
$array = array();
// Set up Variable
$green = "31d944";
$red = "d92929";
$blue = "1b43d9";
$pink = "d96ad8";
$orange = "d98225";
// Loop though - not sure how this would work...
for($i=0; $i<5; $i++){
$array[] = $varNmae => $green;
}
// Output something like below
$array['green']; // output '31d944'
$array['red']; // output 'd92929'
$array['blue']; // output '1b43d9'
$array['pink']; // output 'd96ad8'
$array['orange']; // output 'd98225'