从下面的数组:如何访问一个数组元素,其中的键以PHP中的某个唯一字符串开头?
area = Array
(
sur12 => 2
abb12 => 5
sur13 => 6
abb13 => 4
sur14 => 8
abb14 => 4
sur15 => 2
abb15 => 5
abb16 => 8
abb17 => 5
abb18 => 4
abb19 => 2
abb20 => 6
abb21 => 9
abb22 => 5
abb23 => 9
abb24 => 8
sur_count15 => 4
abb_count24 => 2
)
如何访问area['sur_count15']
如果我只知道前缀sur_count
,或area['abb_count24']
如果我只知道前缀abb_count
?
有什么办法可以在PHP中做到这一点,例如在CSS中,我可以通过使用[id*="abc_count"]
访问以abc_count
开头的ID?
前缀对前3个字符是唯一的。
你有没有考虑过使用'array_keys($ area)'?见http://stackoverflow.com/questions/2471120/php-function-array-key-exists-and-regular-expressions – azhrei 2012-07-18 06:18:41
嗯..谢谢azhrei。将研究这一点。 – 2012-07-18 06:19:38