You are here: Re: array value as array index « PHP Programming Language « IT news, forums, messages
Re: array value as array index

Posted by Rik on 01/25/07 13:35

On Thu, 25 Jan 2007 14:13:50 +0100, Nick Wedd <nick@maproom.co.uk> wrote=
:

> This code
> $cn =3D $ct[$k];
> print "<a name=3D'$ct[$k]'>$continentname[$cn]</a>\n";
> works, and prints something like <a name=3D'af'>Africa</a>
>
> But if I try to simplify it, to
> print "<a name=3D'$ct[$k]'>$continentname[$ct[$k]]</a>\n";
> I get a syntax error
> unexpected '[', expecting ']'
>
> So what is the correct way to write something like $a[$b[$c]] ? I ha=
ve
> tried adding extra {} and '' here and there, so far without success.

Curly braces should work. Tried & tested:
<?php
$bar =3D 'bar';
$foo[$bar] =3D 'baz';
$foz['baz'] =3D 'success';
echo "{$foz[$foo[$bar]]}";
?>

So use print "<a name=3D'$ct[$k]'>{$continentname[$ct[$k]]}</a>\n";
-- =

Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse =

possible errors and weird content. *

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация