1
while(list($key,$val) = each($con_next)) {
    echo " $key $con_next[$key]\n";
}

result is

0 list item 1
1 list item 2
2 list item 3
3 list item 4

but i want result

1 list item 1
2 list item 2
3 list item 3
4 list item 4

2 Answers 2

1

array are default starts from 0 so you have to add 1 to it

echo ($key +1). " $con_next[$key]\n";
Sign up to request clarification or add additional context in comments.

Comments

0

Don't forget that your arrays start counting from 0. An easy solution is to increase your counters. Instead of allowing $key to start count from 1, add +1 to it and it counts 0 + 1, 1 + 1,.... That way you get what you want.

while(list($key,$val) = each($con_next)) {

echo ($key + 1) . "$con_next[$key]\n";

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.