以下是我想要完成的事情
Array
(
[0.94] => 35
[0.93] => 36
[0.92] => 37
[0.91] => 38
.
.
.
[0.50] => 79
)
而不是构建
$arrayName1 = array('0.94' => '35',
'0.93' => '36',
'0.92' => '37',
'0.91' => '38',
'0.50' => '79'
);
我想知道是否有办法为其添加循环以简化流程。任何人吗?
答案 0 :(得分:2)
使用range()
和array_combine()
函数:
$result = array_combine(range(0.94, 0.5, -0.01), range(35, 79));
$result
包含:
Array
(
[0.94] => 35
[0.93] => 36
[0.92] => 37
[0.91] => 38
[0.9] => 39
[0.89] => 40
[0.88] => 41
[0.87] => 42
[0.86] => 43
[0.85] => 44
[0.84] => 45
[0.83] => 46
[0.82] => 47
[0.81] => 48
[0.8] => 49
[0.79] => 50
[0.78] => 51
[0.77] => 52
[0.76] => 53
[0.75] => 54
[0.74] => 55
[0.73] => 56
[0.72] => 57
[0.71] => 58
[0.7] => 59
[0.69] => 60
[0.68] => 61
[0.67] => 62
[0.66] => 63
[0.65] => 64
[0.64] => 65
[0.63] => 66
[0.62] => 67
[0.61] => 68
[0.6] => 69
[0.59] => 70
[0.58] => 71
[0.57] => 72
[0.56] => 73
[0.55] => 74
[0.54] => 75
[0.53] => 76
[0.52] => 77
[0.51] => 78
[0.5] => 79
)
答案 1 :(得分:0)
你可以简单地循环。
[1004/115956.927413:WARNING:dns_config_service_posix.cc(154)] dns_config has unhandled options!
Received signal 11 SEGV_MAPERR 000000000000
[0x000199717cec]
[0x000199717be1]
[0x7fffb7b10b3a]
[0x700006312d88]
[0x000106fa933d]
[0x000106fa933d]
[end of stack trace]