Re: phpsadness

From: Date: Sat, 28 May 2011 20:12:03 +0000
Subject: Re: phpsadness
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-313220@lists.php.net to get a copy of this message
On Sat, May 28, 2011 at 1:34 PM, Andre Polykanine <andre@oire.org> wrote: > Hello Nathan, > > Do you mean $x{8}? > yup, that or $x[8]; > That is good but not for all situations. > I need sometimes to make an array with letters as keys and numbers as > values, like this (I give English alphabet just as an example, so > please don't suggest str_split): > $alphabet="abcdefghijklmnopqrstuvwxyz"; > this just looks like you're after a quick way to populate an array. > // I wish that worked > $alphabet_array=explode('', $alphabet); > $letter_numbers=array_flip($alphabet_array); > do you remember what you needed it for? w/ the array access notation you can get at any letter by index or you can get any index by letter. $alphabet="abcdefghijklmnopqrstuvwxyz"; echo $alphabet[1]; // b echo strpos($alphabet, 'b'); // 1 > this is just one case I encountered some time ago. Yes, I made this by > separating letters with commas... but it's not the unique case when I > need it. It would be nice to hear what the use-case is for this issue. -nathan

« previous php.general (#313220) next »