对于数组的循环

时间:2011-01-01 14:25:54

标签: php

我想使用 for 循环检查数组。检查是否显示选中的值,它也显示其索引。

2 个答案:

答案 0 :(得分:4)

不确定你在问什么,但我的猜测是foreach循环

$array = array("hello" => "world");

foreach($array as $key => $value) {
  echo "This is my index " . $key . " with it's value " . $value;

}

//prints This is my index hello with it's value world

答案 1 :(得分:0)

您可以$key使用foreach获取索引对您有帮助。

for($array as $key=>$value){
if($selectedvalue){
echo $key." ".$value ;

}


}
相关问题