3 ms·
A more "hair friendly" way to modify an array from within a foreach loop is to just use the array key: foreach($array as $key => $value) { if(s
by dools 14y ago
A more "hair friendly" way to modify an array from within a foreach loop is to just use the array key:
foreach($array as $key => $value)
{
if(someCondition($key))
$array[$key] = someTransformation($value);
}
or whatever - ie. just use the key to modify the original array directly. It's much easier to read and see what's happening (in my opinion anyway).