RE: [PHP] Re: why doesn't $books[$val][display] show the value

2002-05-10 Thread Ford, Mike [LSS]

> -Original Message-
> From: Peter J. Schoenster [mailto:[EMAIL PROTECTED]]
> Sent: 10 May 2002 06:40

[]

> http://www.php.net/manual/en/language.types.string.php#language.types.
string.parsing
> 
> Where I see this example (in complex syntax section):
> 
> > // This is wrong for the same reason
> > // as $foo[bar] is wrong outside a string. 
> > echo "This is wrong: {$arr[foo][3]}"; 
> 
> there is no wrong reason above that example.

I think you may be misinterpreting here -- the two comment lines should be read as one 
complete sentence: "This is wrong for the same reason as $foo[bar] is wrong outside a 
string.", so there is, in fact, no reference to a preceding example.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: why doesn't $books[$val][display] show the value

2002-05-09 Thread Peter J. Schoenster

On 9 May 2002 at 15:25, Philip Hallstrom wrote:

> It has to do with precedence (I think).  When inside a double quoted
> string PHP evalutes "$books[$val]" *first* and doesn't catch that
> there's more to it...
> 
> You can do this:
> 
> $html.= " Yaddda yadda " . $books[$val][display];
> 
> And I think this (or something close to it):
> 
> $html.= " Yaddda yadda {$books[$val][display]}";

Yes, I remember someone writing about "how good" it was to do that:

$html.= " Yaddda yadda " . $books[$val][display];

personally I hate it :) ... I use Template::Toolkit in Perl and I 
never muck about with html anything in my Perl. Someone once showed a 
template system in PHP but it required more than I was willing to try 
to do on my virtual server (had to install some Pear stuff on my 
local linux box and move it to my freebsd virtual server and hope :) 

Anyhow, thanks for the clues .. here is what I'm finding now:

http://www.php.net/manual/fi/language.operators.string.php

On the above page someone mentions what you do as well:

> "your choice is {$array['user']['choice']}"

odd thought that he single quoted the key names. I would have thought 
not since everything was in double quotes. Superflous? or necessary?  
Odd, imho. He also talks about better to single quote keys than 
double quote owing to bypassing the need to parse between the single 
quotes. 

He says:

> Generally programmers are better to use ' when ' is applicable to
> avoid parse overhead. For example, use $array['item'] rather than
> $array["item"]. Your script will be executed a bit faster.

I find leads here:

http://www.php.net/manual/en/language.types.string.php#language.types.
string.parsing

Where I see this example (in complex syntax section):

> // This is wrong for the same reason
> // as $foo[bar] is wrong outside a string. 
> echo "This is wrong: {$arr[foo][3]}"; 

there is no wrong reason above that example.

Note the single quote for the literal.  I myself prefer{} and I'll 
single quote all literals contained therein.

And then this is a nice page which kind of goes over the problem. 
I've got a dense head and don't fully understand it all.

http://www.zend.com/zend/tut/using-strings.php

Just following up with comments and links in case someone else gets 
bothered by this (got me for about 15 minutes before I just did what 
I did to get it to work)

Peter
-- http://www.readbrazil.com/
Answering Your Questions About Brazil


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: why doesn't $books[$val][display] show the value

2002-05-09 Thread Philip Hallstrom

It has to do with precedence (I think).  When inside a double quoted
string PHP evalutes "$books[$val]" *first* and doesn't catch that there's
more to it...

You can do this:

$html.= " Yaddda yadda " . $books[$val][display];

And I think this (or something close to it):

$html.= " Yaddda yadda {$books[$val][display]}";

On Thu, 9 May 2002, Peter J. Schoenster wrote:

> Hi,
>
> I've got an array like the following:
>
>   $books = array(
>   "1572316217" => array(
>   category=> 'tech',
>   display => 'Steve McConnell\'s Software Project 
>Survival Guide',
>   href=>
> 'http://www.amazon.com/exec/obidos/ASIN/1572316217/readbrazil07-20',
>   title   => 'Steve McConnell\'s Software Project 
>Survival Guide',
>   width   => '71',
>   height  => '90',
>   src => 
>'/images/1572316217.01.TZZZ.jpg',
>   vspace  => '3',
>   alt => 'Steve McConnell\'s Software 
>Project Survival Guide',
>   hspace  => '3',
>   comments=> "",
>   ),
>
> $books = $AfiliateLinkBuilder->get_books();
> srand ((float) microtime() * 1000);
> $rand_keys = array_rand ($books, 2);
>
> while (list ($key, $val) = each ($rand_keys)) {
>   $display = $books[$val][display];
>
> Why do I have to do this:
>   $display = $books[$val][display];
>
> rather than
>
> $html.= " Yaddda yadda $books[$val][display]";
>
>  $books[$val][display] in the double quotes only shows display. I
> thought that within double quotes I don't use double quotes for
> elements ... ? What's the rule on this. I could do the above in Perl.
>
> Thanks,
>
> Peter
>
>
> -- http://www.readbrazil.com/
> Answering Your Questions About Brazil
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php