Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #12823 > unrolled thread

Array key names

Started byJohn Smith <JohnSmith@example.com>
First post2014-02-14 00:40 -0500
Last post2014-02-14 15:09 +0100
Articles 7 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  Array key names John Smith <JohnSmith@example.com> - 2014-02-14 00:40 -0500
    Re: Array key names "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-02-14 10:49 +0100
      Re: Array key names richard <noreply@example.com> - 2014-02-14 06:43 -0500
        Re: Array key names Scott Johnson <noonehome@chalupasworld.com> - 2014-02-14 05:43 -0800
        Re: Array key names "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-02-14 18:28 +0100
        Re: Array key names Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-14 19:05 +0000
    Re: Array key names Christoph Michael Becker <cmbecker69@arcor.de> - 2014-02-14 15:09 +0100

#12823 — Array key names

FromJohn Smith <JohnSmith@example.com>
Date2014-02-14 00:40 -0500
SubjectArray key names
Message-ID<1864yi9o87hzd$.13eojppqkwixm$.dlg@40tude.net>
Just one simple question. Are spaces allowed in key names?
Such as $name=array("John Smith" +> "somethig").

[toc] | [next] | [standalone]


#12824

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-02-14 10:49 +0100
Message-ID<bm675oFtgk9U1@mid.uni-berlin.de>
In reply to#12823
Am 14.02.2014 06:40, schrieb John Smith:
> Just one simple question. Are spaces allowed in key names?
> Such as $name=array("John Smith" +> "somethig").
> 


I am testing it for you.

str@suse131:~> php -a
Interactive mode enabled

php > $a['is it really me?'] = 99.999;
php > print_r($a);
Array
(
    [is it really me?] => 99.999
)
php >

/Str.

[toc] | [prev] | [next] | [standalone]


#12826

Fromrichard <noreply@example.com>
Date2014-02-14 06:43 -0500
Message-ID<1f5dmj1ajrueb.q6jlzpybxgfj.dlg@40tude.net>
In reply to#12824
On Fri, 14 Feb 2014 10:49:44 +0100, M. Strobel wrote:

> Am 14.02.2014 06:40, schrieb John Smith:
>> Just one simple question. Are spaces allowed in key names?
>> Such as $name=array("John Smith" +> "somethig").
>> 
> 
> 
> I am testing it for you.
> 
> str@suse131:~> php -a
> Interactive mode enabled
> 
> php > $a['is it really me?'] = 99.999;
> php > print_r($a);
> Array
> (
>     [is it really me?] => 99.999
> )
> php >
> 
> /Str.

You Probably just typed it all in without any online testing.
The only true way of testing what is allowed and what isn't, is to do so on
the server you're going to be using.
e.g. your local machine you are using to test on at home has php 5.5.
while your host uses 5.3.
What worked for you suddenly fails.

[toc] | [prev] | [next] | [standalone]


#12827

FromScott Johnson <noonehome@chalupasworld.com>
Date2014-02-14 05:43 -0800
Message-ID<ldl6p3$bna$1@dont-email.me>
In reply to#12826
On 2/14/14, 3:43 AM, richard wrote:
> On Fri, 14 Feb 2014 10:49:44 +0100, M. Strobel wrote:
>
>> Am 14.02.2014 06:40, schrieb John Smith:
>>> Just one simple question. Are spaces allowed in key names?
>>> Such as $name=array("John Smith" +> "somethig").
>>>
>>
>>
>> I am testing it for you.
>>
>> str@suse131:~> php -a
>> Interactive mode enabled
>>
>> php > $a['is it really me?'] = 99.999;
>> php > print_r($a);
>> Array
>> (
>>      [is it really me?] => 99.999
>> )
>> php >
>>
>> /Str.
>
> You Probably just typed it all in without any online testing.
> The only true way of testing what is allowed and what isn't, is to do so on
> the server you're going to be using.
> e.g. your local machine you are using to test on at home has php 5.5.
> while your host uses 5.3.
> What worked for you suddenly fails.
>

richard I would be very careful telling others who have obviously more 
experience then you in PHP on how to and not to do coding/testing in 
PHP.  You may not really know enough about what you think you know.  I 
learned that some time ago.

For starters, Strobel is using what is called command prompt.  Great for 
testing a snippet of code without loading up the editor and such.

Secondly the OP is asking a simple question, which he could of actually 
tested on his own, and Strobel is wise enough to understand it was not 
affected by a minor version release.

Scotty

[toc] | [prev] | [next] | [standalone]


#12831

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2014-02-14 18:28 +0100
Message-ID<bm7211F4njaU1@mid.uni-berlin.de>
In reply to#12826
Am 14.02.2014 12:43, schrieb richard:
> On Fri, 14 Feb 2014 10:49:44 +0100, M. Strobel wrote:
> 
>> Am 14.02.2014 06:40, schrieb John Smith:
>>> Just one simple question. Are spaces allowed in key names?
>>> Such as $name=array("John Smith" +> "somethig").
>>>
>>
>>
>> I am testing it for you.
>>
>> str@suse131:~> php -a
>> Interactive mode enabled
>>
>> php > $a['is it really me?'] = 99.999;
>> php > print_r($a);
>> Array
>> (
>>     [is it really me?] => 99.999
>> )
>> php >
>>
>> /Str.
> 
> You Probably just typed it all in without any online testing.
> The only true way of testing what is allowed and what isn't, is to do so on
> the server you're going to be using.
> e.g. your local machine you are using to test on at home has php 5.5.
> while your host uses 5.3.
> What worked for you suddenly fails.
> 

Yes, I just typed it in :-) something I invite everybody to do.

And - the OP did not ask for a specific version.

And - this will not fail, it is too basic.

... (skip the rest about richard@noreplay as sysadmin)

/Str.

[toc] | [prev] | [next] | [standalone]


#12833

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-02-14 19:05 +0000
Message-ID<ldlpd7$e0g$1@dont-email.me>
In reply to#12826
On Fri, 14 Feb 2014 06:43:54 -0500, richard wrote:

> You Probably just typed it all in without any online testing.

Dipshit, we just had this fucking conversation. Piss off home and leave 
the technical help and advice to people who know what they're talking 
about, there's a good ignoramus.

For the OP, who hopefully has ignored every piece of claptrap richard has 
spoken:

A string style array index can comprise any valid sequence of string 
characters, including escape sequences for things such as tab, newline 
etc. It's a string, it can contain the same as any other string, the fact 
that it's being used as an array index does not change it's basic 
stringiness.

Indeed there's no reason not to do this, apart from it would be a really 
weird thing to do:

<?php

$_POST = array( "monkey" =>"\t\tsomething\t\t" );

$i = <<< EOT
This is my really long string array index.

It has several lines. In here I'm adding some post data:

The post data is the value of the monkey form field: '{$_POST['monkey']}'

That's a very bad example to give, because I'm using unvalidated and 
unverified user input. Jerry will call me out on this, and rightly so.

Meanwhile, here are some other things \n\n\n\n\n\t\t\t\t\t\nStuff

"and nonsense"

!!!!!!!!!!! <- madness

EOT;

$x = array( $i => "fred" );

var_dump( $x );

?>

Note - if you ever actually use an array key like that in production code 
then you deserve all the future pain and suffering that your code is 
surely going to cause you when it rises up as the toilet dragon of 
unhappiness and bites you very hard on the buttocks.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#12828

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-02-14 15:09 +0100
Message-ID<52fe23ac$0$6661$9b4e6d93@newsspool2.arcor-online.net>
In reply to#12823
John Smith wrote:

> Just one simple question. Are spaces allowed in key names?
> Such as $name=array("John Smith" +> "somethig").

Actually, *any* string is allowed as key, however, not all strings will
be treated as string keys[1].

[1] <http://www.php.net/manual/en/language.types.array.php#example-83>

-- 
Christoph M. Becker

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web