| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Joe wrote: > Is there a way to determine if an array is associative or not? Maybe > something similar to the is_array() function ?? There are only assotiative arrays in PHP. regards Wagner -- Assumption is the mother of all fuck-ups. |
|
#2
| |||
| |||
| On Fri, Mar 16, 2001 at 11:43:17PM +0100, Alexander Wagner wrote: > Joe wrote: > > Is there a way to determine if an array is associative or not? Maybe > > something similar to the is_array() function ?? > > There are only assotiative arrays in PHP. PHP has associative and numeric (normal) arrays. But is_array() says only if it is an array or not. The distinction could only be made if you look at keys. Keys can be integers or strings. I hope this was correct, if not, Andrei can correct me ![]() -Egon -- http://www.linuxtag.de/ http://php.net/books.php http://www.concert-band.de/ http://www.php-buch.de/ |
|
#3
| |||
| |||
| eschmid+sic@s.netic.de wrote: > > There are only assotiative arrays in PHP. > > PHP has associative and numeric (normal) arrays. But is_array() says > only if it is an array or not. The distinction could only be made if > you look at keys. Keys can be integers or strings. I hope this was > correct, if not, Andrei can correct me ![]() If I'm not completely mistaken, PHP has only associative arrays, which can act more or less like "normal" indexed arrays when numbers are used as keys, which is the default when no keys are set explicitly, like in: $arr = array('a', 'b', 'c'); which equals $arr = array(0 => 'a', 1 => 'b', 2 => 'c'); But they are still associative, afaik. However, I agree, the only way to make a distinction is to look if the keys are integers. regards Wagner -- Assumption is the mother of all fuck-ups. |
|
#4
| |||
| |||
| what do you mean? all arrays are associative. even the simple $arr = array(1,2,3,4,5); has key/value pairs associated with it.. similar to doing: $arr = array(0=>1,1=>2,2=>3,3=>4,4=>5); --- Joe <joe@mail.nitewaryr.com> wrote: > Is there a way to determine if an array is associative or not? Maybe > something similar to the is_array() function ?? > > Thanks, > > JOE > __________________________________________________ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ |
|
#5
| |||
| |||
| No functions that I can think of but you can write one like this: $arrayType = 'numeric'; foreach($myArray as $key => $value) { if(!is_numeric($key)) { $arrayType = 'associative'; } } Also remember that an array can be both! Larry > Is there a way to determine if an array is associative or not? Maybe = > something similar to the is_array() function ?? |
|
#6
| |||
| |||
| All arrays in PHP are associative; we sometimes use integers to refer to them, but the order of the array internally is not necessarily the same as the integers; indeed, any array can have "holes" in them. So the question is moot. "There are no different indexed and associative array types in PHP, there is only one array type, which can both contain integer and string indices." - http://www.php.net/manual/en/language.types.array.php Mark C. > > Is there a way to determine if an array is associative or not? Maybe = > > something similar to the is_array() function ?? > |
|
#7
| |||
| |||
| Fix your clock! Post like theese really screws up the layout in my newsreader! -- Kim Steinhaug --------------------------------------------------------------- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --------------------------------------------------------------- "Joe" <joe@mail.nitewaryr.com> wrote in message news:001901d3bd6f$da2bcf00$0200a8c0@dsl.inconnect. com... Is there a way to determine if an array is associative or not? Maybe something similar to the is_array() function ?? Thanks, JOE |
|
#8
| |||
| |||
| Is there a way to determine if an array is associative or not? Maybe something similar to the is_array() function ?? Thanks, JOE |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.