Re: Why Can't I "define" a Value for a Subscript? PS [message #175239 is a reply to message #175236] |
Sun, 28 August 2011 19:53 |
Norman Peelman
Messages: 126 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 08/28/2011 03:36 PM, eBob.com wrote:
> I did a simple experiment that I thought might shed some light on this.
> But instead I just increased my confusion.
>
> I tried the following ...
>
> define('SS1SITE',0);
> echo 'ss1site is: '. "SS1SITE\n";
>
> and the output is ...
>
> ss1site is: SS1SITE
>
> My book says that variable substitution happens within double quotes and
> in my limited experience that is true.
>
> Why isn't the variable substitution happening in this case?
>
> Thanks, Bob
>
> "eBob.com" <eBob(dot)com(at)totallybogus(dot)com> wrote in message
> news:Cvw6q(dot)176718$k33(dot)110045(at)en-nntp-13(dot)dc1(dot)easynews(dot)com...
>> I am working with some csv files. To make the program more
>> maintainable and more self-documenting I "define" values to use as
>> subscripts; e.g. ...
>>
>> define('SS2KEY',0);
>>
>> BUT, whereas this produces what I expected ...
>>
>> echo "we have a match - key: $file2cols[0]\n";
>>
>> ... this does not ...
>>
>> echo "we have a match - key: $file2cols[SS2KEY]\n";
>>
>> I see the other text but no value is substitited for $file2cols[SS2KEY]
>>
>> I've wasted so much time on this. Why can't I define constants to use
>> as subscripts?
>>
>> Thanks, Bob
>
You can. Try:
echo 'we have a match - key: ',$file2cols[SS2KEY],"\n";
or
echo "we have a match - key: {$file2cols[SS2KEY]}\n";
You must use curly braces around (multi-dimensional) array variables
and constant keys in strings.
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
|
|
|