How to iterate over array with indexes and values in PHP

1 Answer

0 votes
$arr = array("php", "c", "c++", "java");

foreach ($arr as $i => $v) {
    echo "index = $i value = $v" . "\n";
}




/*
run:

index = 0 value = php
index = 1 value = c
index = 2 value = c++
index = 3 value = java

*/

 



answered Jan 13, 2023 by avibootz

Related questions

2 answers 317 views
1 answer 284 views
1 answer 272 views
1 answer 245 views
1 answer 225 views
3 answers 400 views
1 answer 275 views
...