You are here: Re: PHP and Arrays? « PHP Programming Language « IT news, forums, messages
Re: PHP and Arrays?

Posted by Marcin Dobrucki on 09/16/05 11:00

ZeldorBlat wrote:
> Oli is correct, although you can probably "cheat" with something like
> this:
>
> function array_is_simple(&$arr) {
> if(!is_array($arr))
> return false;
>
> $keys = array_keys($arr);
> foreach($keys as $x)
> if(!is_numeric($x) || intval($x) != $x)
> return false;
>
> return true;
> }

As Oli pointed out, this will only let you cheat half way. Is this a
"simple array" or a "hash":

array (0 => "foo",
1 => "bar",
3 => "good question");

The function above returns true, but I would rather call it a hash.

Similarly, this will return true:

array (0 => "foo",
1.1 => "bar);

However, the indexing is more of a hash than index.

You could further try to cheat by extending "array_is_simple" to
check for consecutiveness and for non-int values, but what is this:

$array3 = array ("0" => "first elemement",
"1" => "second elemeent",
"2" => "third element");

Array_is_simple will return true, but this is actually a hash.

/Marcin

 

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

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