Re: [PHP] EZ array problem - What's wrong with my brain?
Youri LACAN-BARTLEY wrote: Hi Jochem, I meant overly-complicated in this specific context. If each key of this array is going to contain only one value why not reduce the array to something like this : array(1) { [1.2]= array(2) { [code]= string(3) 111 [status]= string(3) new } } That's all I was referring to ... ah yes - I can see your point! Jochem Maas wrote: Youri LACAN-BARTLEY wrote: Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. I must say this looks like an overly complicated array for what it serves. A little OOP could come in handy to organize all that in more friendly and efficient way ... efficient? overly-complicated? php arrays are made for stuff like this. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
Richard Lynch wrote: On Fri, December 1, 2006 9:28 am, Ray Hauge wrote: I forgot to mention that you won't be able to use 0, 1, etc. as PHP will convert those to integers. If you do use them, then they will replace [0] with whatever you put in there, and if you are using the references, it will replace both instances with your new [0] You can type-cast to (string) to force a string key. $foo[(string) '1'] = 'foo'; should, I think, have a string key... At least I know for sure that it works for float keys... You'll have to try it and see for '1' -- I could be way off base. in cases whether the key you are 'looking up' is numeric php doesn't care whether you use an integer or string - as far as php is concerned 1 and 1 point to exactly the same array item: php -r '$v = array(foo,bar); var_dump($v[0],$v[0], $v[1], $v[1]);' I find this quite handy - though it does help to actually know about this particular behaviour :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
2006/11/30, Brian Dunning [EMAIL PROTECTED]: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $keys = array_keys($var); var_dump($keys[0]); string(3) 1.2 $values = array_values($var); var_dump($values[0]); array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } }
Re: [PHP] EZ array problem - What's wrong with my brain?
Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. I must say this looks like an overly complicated array for what it serves. A little OOP could come in handy to organize all that in more friendly and efficient way ... Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
Youri LACAN-BARTLEY wrote: Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. I must say this looks like an overly complicated array for what it serves. A little OOP could come in handy to organize all that in more friendly and efficient way ... efficient? overly-complicated? php arrays are made for stuff like this. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
Try $try = $var[1.2]; If your array looks like the one below then there is no $var[0] and therefore you get NULL /Thunis Brian Dunning skrev: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
Hi Jochem, I meant overly-complicated in this specific context. If each key of this array is going to contain only one value why not reduce the array to something like this : array(1) { [1.2]= array(2) { [code]= string(3) 111 [status]= string(3) new } } That's all I was referring to ... Jochem Maas wrote: Youri LACAN-BARTLEY wrote: Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. I must say this looks like an overly complicated array for what it serves. A little OOP could come in handy to organize all that in more friendly and efficient way ... efficient? overly-complicated? php arrays are made for stuff like this. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
That works, but the value 1.2 is unknown, I can't hardcode it. On Dec 1, 2006, at 6:52 AM, Fredrik Thunberg wrote: Try $try = $var[1.2]; If your array looks like the one below then there is no $var[0] and therefore you get NULL /Thunis Brian Dunning skrev: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] EZ array problem - What's wrong with my brain?
http://www.php.net/manual/en/language.types.array.php If you check out the documentation on arrays, you will see the second code example shows the expected behavior of arrays in this case. $arr = array(foo = bar, 12 = true); echo $arr[foo]; // bar echo $arr[12];// 1 Now, since each element can be indexed by either a string or an integer, then you can do something like this: $arr = array(1.2 = array(1,2,3,4)); $arr[0] = $arr[1.2]; That would set up your doubly indexed array so that you could use either associative keys or numeric keys. http://www.php.net/manual/en/language.references.php PHP.net can explain how references work better than I can. Basically it creates a symbolic link (to use a *nix term) to the key 1.2. It shouldn't take up too much memory to do that. -- Ray Hauge Application Development Lead American Student Loan Services www.americanstudentloan.com -Original Message- From: Fredrik Thunberg [mailto:[EMAIL PROTECTED] Sent: Friday, December 01, 2006 8:52 AM To: Brian Dunning; php-general@lists.php.net Subject: Re: [PHP] EZ array problem - What's wrong with my brain? Try $try = $var[1.2]; If your array looks like the one below then there is no $var[0] and therefore you get NULL /Thunis Brian Dunning skrev: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] EZ array problem - What's wrong with my brain?
I forgot to mention that you won't be able to use 0, 1, etc. as PHP will convert those to integers. If you do use them, then they will replace [0] with whatever you put in there, and if you are using the references, it will replace both instances with your new [0] HTH -- Ray Hauge Application Development Lead American Student Loan Services www.americanstudentloan.com -Original Message- From: Ray Hauge Sent: Friday, December 01, 2006 9:21 AM To: Fredrik Thunberg; Brian Dunning; php-general@lists.php.net Subject: RE: [PHP] EZ array problem - What's wrong with my brain? http://www.php.net/manual/en/language.types.array.php If you check out the documentation on arrays, you will see the second code example shows the expected behavior of arrays in this case. $arr = array(foo = bar, 12 = true); echo $arr[foo]; // bar echo $arr[12];// 1 Now, since each element can be indexed by either a string or an integer, then you can do something like this: $arr = array(1.2 = array(1,2,3,4)); $arr[0] = $arr[1.2]; That would set up your doubly indexed array so that you could use either associative keys or numeric keys. http://www.php.net/manual/en/language.references.php PHP.net can explain how references work better than I can. Basically it creates a symbolic link (to use a *nix term) to the key 1.2. It shouldn't take up too much memory to do that. -- Ray Hauge Application Development Lead American Student Loan Services www.americanstudentloan.com -Original Message- From: Fredrik Thunberg [mailto:[EMAIL PROTECTED] Sent: Friday, December 01, 2006 8:52 AM To: Brian Dunning; php-general@lists.php.net Subject: Re: [PHP] EZ array problem - What's wrong with my brain? Try $try = $var[1.2]; If your array looks like the one below then there is no $var[0] and therefore you get NULL /Thunis Brian Dunning skrev: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
Well if the key of your array is unknown, you could always gather the key names with array_keys() and fiddle something from there or just change the structure of you array to be more adapted to you needed or use what Ray just proposed in another post concerning references and the creation of a numeric key as a symbolic link towards your string key ... Good luck ! Brian Dunning wrote: That works, but the value 1.2 is unknown, I can't hardcode it. On Dec 1, 2006, at 6:52 AM, Fredrik Thunberg wrote: Try $try = $var[1.2]; If your array looks like the one below then there is no $var[0] and therefore you get NULL /Thunis Brian Dunning skrev: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] EZ array problem - What's wrong with my brain?
There is no $var[0]; It's $var['1.2]; There is no $var[0][0]; It's $var['1.2']['code']; The remainder of this email composition is left as an exercise for the reader. On Fri, December 1, 2006 8:46 am, Brian Dunning wrote: That seems right to me too - but everything I try returns NULL. I set $try=$var[0], and $try ends up being null; print_r($try) gives blank. I even tried $try=$var[1] and it was the same result. Am I in the Twilight Zone? On Dec 1, 2006, at 12:26 AM, Youri LACAN-BARTLEY wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, I've only just fallen out of bed, but I'd say you'd be able to access it via $var[0][0][0] as in $var[1.2][code][0] to change 111 to something else and $var[1.2][status][0] to set/change new. Brian Dunning wrote: var_dump() gives me this: array(1) { [1.2]= array(2) { [code]= array(1) { [0]= string(3) 111 } [status]= array(1) { [0]= string(3) new } } } I'm trying to set a variable to that 1.2. Shouldn't I be able to get it with $var = $arr[0][0]? --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFb+cnWC9/YPePNU4RAmnzAKDGUlHxZiQvyhLfSiHKXV9sI73fTQCfe/Ub pKYeQqK4FcNhmTdEIm41kic= =PSbi -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] EZ array problem - What's wrong with my brain?
On Fri, December 1, 2006 9:28 am, Ray Hauge wrote: I forgot to mention that you won't be able to use 0, 1, etc. as PHP will convert those to integers. If you do use them, then they will replace [0] with whatever you put in there, and if you are using the references, it will replace both instances with your new [0] You can type-cast to (string) to force a string key. $foo[(string) '1'] = 'foo'; should, I think, have a string key... At least I know for sure that it works for float keys... You'll have to try it and see for '1' -- I could be way off base. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php