> ''Phoenix'',
''Alaska'' => ''Juneau'',
''Alabama'' => ''Montgomery''
);
$state = array_search(''Juneau'', $capitals);
// $state = ''Alaska''
10、使用php标准函数库
一口气介绍这个多操作array的函数,如果您还觉得不过瘾,可以继续查看Standard PHP Library 中的内容^_^
复制代码 代码如下:
$capitals = array(
''Arizona'' => ''Phoenix'',
''Alaska'' => ''Juneau'',
''Alabama'' => ''Montgomery''
);
$arrayObject = new ArrayObject($capitals);
foreach ($arrayObject as $state => $capital)
{
printf("The capital of %s is %s<br />", $state, $capital);
}
// The capital of Arizona is Phoenix
// The capital of Alaska is Juneau
// The capital of Alabama is Montgomery