MadnessRed Posted March 24, 2009 Share Posted March 24, 2009 I have a foreach loop as shown below. foreach($d as $i => $a){ $d[$i] *= $percent; } whilst this code works fine when I use analyse code I get the following The variable assigned to $a is never used This is the 1 error in the script so I was wondering if there was a way that would avoid having to declare $a, eg foreach($d as $i => NULL){ Link to comment https://forums.phpfreaks.com/topic/150942-foreach-loop-just-getting-the-keys/ Share on other sites More sharing options...
Mark Baker Posted March 24, 2009 Share Posted March 24, 2009 Take a look at the array_keys() function foreach(array_keys($d) as $i) { $d[$i] *= $percent; } or consider using array_walk() Link to comment https://forums.phpfreaks.com/topic/150942-foreach-loop-just-getting-the-keys/#findComment-792988 Share on other sites More sharing options...
rhodesa Posted March 24, 2009 Share Posted March 24, 2009 i would ignore the error...as all other options i can think of use more processing Link to comment https://forums.phpfreaks.com/topic/150942-foreach-loop-just-getting-the-keys/#findComment-792990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.