Associative vs normal arrays

This is a discussion on Associative vs normal arrays within the PHP forums in Programming Languages category; 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....

Go Back   Application Development Forum > Programming Languages > PHP

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 03-16-2001, 05:43 PM
Alexander Wagner
Guest
 
Default Re: [PHP] Associative vs normal arrays

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.

Reply With Quote
  #2  
Old 03-16-2001, 06:01 PM
eschmid+sic@s.netic.de
Guest
 
Default Re: [PHP] Associative vs normal arrays

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/
Reply With Quote
  #3  
Old 03-16-2001, 09:44 PM
Alexander Wagner
Guest
 
Default Re: [PHP] Associative vs normal arrays

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.
Reply With Quote
  #4  
Old 03-17-2001, 06:06 AM
Yev
Guest
 
Default Re: [PHP] Associative vs normal arrays

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/
Reply With Quote
  #5  
Old 02-02-2003, 12:33 PM
no-spam----me@larrykagan.com
Guest
 
Default Re: Associative vs normal arrays

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 ??



Reply With Quote
  #6  
Old 02-02-2003, 03:39 PM
Mark Charette
Guest
 
Default RE: [PHP] Re: Associative vs normal arrays

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 ??

>


Reply With Quote
  #7  
Old 11-27-2003, 02:47 PM
Kim Steinhaug
Guest
 
Default Re: Associative vs normal arrays

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
Reply With Quote
  #8  
Unread 03-16-2018, 05:43 PM
Joe
Guest
 
Default Associative vs normal arrays

Is there a way to determine if an array is associative or not? Maybe something similar to the is_array() function ??

Thanks,

JOE

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:12 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.