I just want to avoid to turn off the E_NOTICE from the php.ini in order to handle large arrays when they are not set.
foreach ($rowset1 as $row) {
if ( ! isset($stats['user'][$row['insertedBy']]['a']['xxx'])) {
$stats['user'][$row['insertedBy']]
['a']['xxx'] = $row['xxx'];
}else{
$stats['user'][$row['insertedBy']]
['a']['xxx'] += $row['xxx'];
}
}
foreach ($rowset2 as $row) {
if ( ! isset($stats['user'][$row['insertedBy']]['b']['xxx'])) {
$stats['user'][$row['insertedBy']]
['b']['yyy'] = $row['xxx'];
}else{
$stats['user'][$row['insertedBy']]
['b']['yyy'] += $row['xxx'];
}
}
I just want to write the arrays keys inside the loops, just once, like I would do it if I wouldn't have the E_NOTICE turned on.
No, you really don't want to turn off that notice. This isn't the only thing you will get notices on. Just add the simple extra line to deal with it, or if you find it is a common set of code you are writing over and over and over, encode it in a function. The notice is telling you that something fishy is happening with your code. Don't let your code smell... you will regret it later.
Example: pass the array in by reference, you only have a difference of 'a' and 'b' between the two loops