You are here: Re: problems changing point for coma... « PHP Programming Language « IT news, forums, messages
Re: problems changing point for coma...

Posted by David Haynes on 03/08/06 13:11

Toby Inkster wrote:
> David Haynes wrote:
>
>> Iteration by indexing works and is, as I said, brute force.
>
> Iteration by indexing works *iff* all your indexes are numeric and
> sequential. Your for-loop won't work on non-sequential arrays like this:
>
> array(
> 0 => '123,45',
> 1 => '123,45',
> 9 => '123,45'
> );
>
> because count() will return 3, meaning that the last element of the array,
> with index 9, won't be touched. Nor will it work on:
>
> array(
> -1 => '123,45',
> 0 => '123,45',
> 1 => '123,45'
> );
>
> as your for-loop has a hard-coded start value of 0. Nor will it work on:
>
> array(
> 'a' => '123,45',
> 'b' => '123,45',
> 'c' => '123,45'
> );
>
> because the keys aren't numeric. Iván's foreach-loop will work on all of
> these three examples.
>
Tony,
Thank you for a well presented response. I guess I tend to treat
associative and numeric arrays differently (in my own head) and so would
not even have thought of using a for() on an associative array, but the
difficulties with non-zero origin and sparse data are real.

Lesson learned.
-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация