PHP does not have different primitive types for arrays and structs. It is all an array. The only difference is, that a list contains just ascending integers as keys, starting from zero, the rest is a struct.
<?php
if (array_keys($array) === range(0, count($array) - 1)) {
// Is an array
} else {
// Is a struct
}
In the Zend Framework this differentiation is needed in the XmlRpc-component. I’ve submitted a patch to make it more efficient.
Comments
Show comments linear or threaded
Marc Jakubowski answers:
published on 2007|10|22, 10:14hIch weiß nicht wie das Array in der Regel aussieht, aber sobald dann bei nem numerischen Array Lücken auftauchen (array(0=>‘a’, 2=>‘b’) klappts natürlich nicht mehr.
Lars Strojny returns:
published on 2007|10|22, 14:22hHat man ja normalerweise nicht. Also wenn irgendein Tool ein array(2 => "Foo", 4 => "bla") zurückgibt, ist das Tool futsch, IMHO.
Add comment