Re: Q: Array

From: Date: Fri, 11 Jan 2002 19:10:14 +0000
Subject: Re: Q: Array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-80224@lists.php.net to get a copy of this message
Hi again Michael: Digging documentation I found out that this behaviour (string and int keys) is native for mysql_fetch_arrow() (found into the help: 'In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys. ') So the question is answered. Thank you for your help. Best regards Ivo "Michael Sims" <mhsims@midsouth.rr.com> wrote in message news:5.1.0.14.0.20020110183411.03e18070@pop-server.midsouth.rr.com... > At 09:18 PM 1/10/2002 +0100, Ivo Stoykov wrote: > >How could I determine whether I have in the array's key integers *and* > >strings or integers only? > > I'm not sure exactly what you're asking but I'll give it a shot... > > >i.e. > >$a = new array('one', 'two', 'three'); // this has only > >integers (am I > >wrong?) > > First of all, the "new" keyword assumes that you are instantiating an > object. For example if you created an object with the name foo you would > instantiate it like so: > > $a = new foo; > > So when creating arrays the "new" keyword is undesirable. > > To address your question, yes your example above (after removing the "new" > keyword) will create an array named $a that has only integers for > keys. It's functionally the same as this: > > $a = array(0 => 'one', 1 => 'two', 2 => 'three'); > > >$b = new array('one' => 'bla', 'two' => > >'blabla', 'three' => 'blablabla'); > >// integers & strings > > The above example (again once corrected to remove the "new" keyword) will > create an array named $b that has ONLY strings for keys. There are no keys > that are integers because you didn't create any. You can test this by > trying to echo the values out by key: > > echo $b['one']; //outputs "bla" > echo $b[0]; //outputs nothing because this key does not have a value. > > This is perfectly legal: > > $b = array ('one' => 'bla', 'two' => 'blabla', > 'three' => 'blablabla', 0 => > 'blablablabla', > 1 => 'blablablablabla'); > > In the above case you do have some keys that are strings and some that are > integers but they are DIFFERENT keys, representing DIFFERENT values. > > Hope that answers your question... >

« previous php.general (#80224) next »