2

Possible Duplicate:
php - get numeric index of associative array

$array = ('a'=>'a', 'b'=>'b');
foreach($array as $key => $value ){
   //echo $position ( 1,2 )
}

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

0

2 Answers 2

1

Try:

$i = 0;
$array = ('a'=>'a', 'b'=>'b');
foreach($array as $key => $value ){
   $i++;
   echo $i;
}
Sign up to request clarification or add additional context in comments.

1 Comment

You can skip one line of code by using echo ++$i;. See Incrementing/Decrementing Operators for more information.
0
$array = array('a'=>'a', 'b'=>'b');
for ($x = 0; $x < count($array);$x++)
        echo $x."<br >";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.