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 312 views
1 answer 280 views
1 answer 268 views
1 answer 242 views
1 answer 223 views
3 answers 396 views
1 answer 273 views
...