2
可能性の重複:
php - get numeric index of associative arrayPHP連想配列の位置を取得するには?
$array = ('a'=>'a', 'b'=>'b');
foreach($array as $key => $value){
//echo $position (1,2)
}
私は簡単な関数で、配列内の位置を取得することはできますか?
可能性の重複:
php - get numeric index of associative arrayPHP連想配列の位置を取得するには?
$array = ('a'=>'a', 'b'=>'b');
foreach($array as $key => $value){
//echo $position (1,2)
}
私は簡単な関数で、配列内の位置を取得することはできますか?
試してみてください。
$i = 0;
$array = ('a'=>'a', 'b'=>'b');
foreach($array as $key => $value){
$i++;
echo $i;
}
$array = array('a'=>'a', 'b'=>'b');
for ($x = 0; $x < count($array);$x++)
echo $x."<br >";
あなたは$ ++エコー 'Iを使用することにより、コードの1行をスキップすることができ;'。詳細については、[Incrementing/Decrementing Operators](http://php.net/manual/en/language.operators.increment.php)を参照してください。 – Treffynnon