I read in a few different articles that using array_keys() in foreach loops increases performance, but in practice I really don’t notice any increase in speed of my code when using array_keys() on large arrays.
example:
foreach(array_keys($myArray) as $ak){
$arrayElement =& $myArray[$ak];
//do whatever I need to do with massive array ...
}
It is somewhat logical to have some performance gain with large arrays – yes. That way PHP will only copy the array keys in the loop as opposed to keys+values, resulting in a less memory-intensive procedure.
However, as it’s been noted in the comments section – it’s not something that you’ll usually notice. It’s deffinately a good practice to make a habit for those things, but you can’t actually see it outside of benchmark scores unless you’re writing a fairly complex/heavy script.