Array key names [message #184896] |
Fri, 14 February 2014 05:40 |
John Smith
Messages: 7 Registered: January 2014
Karma: 0
|
Junior Member |
|
|
Just one simple question. Are spaces allowed in key names?
Such as $name=array("John Smith" +> "somethig").
|
|
|
Re: Array key names [message #184897 is a reply to message #184896] |
Fri, 14 February 2014 09:49 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Array key names [message #184899 is a reply to message #184897] |
Fri, 14 February 2014 11:43 |
Mr Oldies
Messages: 241 Registered: October 2013
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Array key names [message #184900 is a reply to message #184899] |
Fri, 14 February 2014 13:43 |
Scott Johnson
Messages: 196 Registered: January 2012
Karma: 0
|
Senior Member |
|
|
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
|
|
|
|
Re: Array key names [message #184904 is a reply to message #184899] |
Fri, 14 February 2014 17:28 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Array key names [message #184906 is a reply to message #184899] |
Fri, 14 February 2014 19:05 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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(at)gmail(dot)com
|
|
|