PHP equivalent to Python's enumerate()?
Don't trust PHP arrays, they are like Python dicts. If you want safe code consider this:
<?php$lst = array('a', 'b', 'c');// Removed a value to prove that keys are preservedunset($lst[1]);// So this wont workforeach ($lst as $i => $val) { echo "$i $val \n";}echo "\n";// Use array_values to reset the keys insteadforeach (array_values($lst) as $i => $val) { echo "$i $val \n";}?>
-
0 a 2 c 0 a 1 c