开发者

How to get position in a php associative array? [duplicate]

开发者 https://www.devze.com 2023-03-23 13:53 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: php - get numeric index of associative array
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

php - get numeric index of associative array

$array = ('开发者_如何学JAVAa'=>'a', 'b'=>'b');
foreach($array as $key => $value ){
   //echo $position ( 1,2 )
}

Can I get the position in the array with a simple function ?


Try:

$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 >";
0

精彩评论

暂无评论...
验证码 换一张
取 消