Re: phpsadness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, May 28, 2011 at 1:34 PM, Andre Polykanine <andre@xxxxxxxx> 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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux