|  | 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
 [Back to original message] |