|
Posted by Mike Ford on 01/13/05 19:54
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
On 13 January 2005 05:28, Matthew Fonda wrote:
> use the unset() function.
>
> for ($i = 0; $i < count($array); $i++) {
> if (empty($array[$i]) {
> unset($array[$i]);
> }
> }
Without actually running it (I'm too lazy!), I'm pretty sure this won't work
correctly -- the count($array) is being recalculated each time round the
loop, so each time you do an unset() it will reduce by one, resulting in the
last few elements never being checked.
It should, however, be perfectly possible to use foreach in the same way:
foreach ($array as $i=>$value) {
if (empty($value]) {
unset($array[$i]);
}
}
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Navigation:
[Reply to this message]
|