array value as array index

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Wedd

    #1

    array value as array index

    This code
    $cn = $ct[$k];
    print "<a name='$ct[$k]'>$continentnam e[$cn]</a>\n";
    works, and prints something like <a name='af'>Afric a</a>

    But if I try to simplify it, to
    print "<a name='$ct[$k]'>$continentnam e[$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 have
    tried adding extra {} and '' here and there, so far without success.

    Nick
    --
    Nick Wedd nick@maproom.co .uk
  • Rik

    #2
    Re: array value as array index

    On Thu, 25 Jan 2007 14:13:50 +0100, Nick Wedd <nick@maproom.c o.ukwrote:
    This code
    $cn = $ct[$k];
    print "<a name='$ct[$k]'>$continentnam e[$cn]</a>\n";
    works, and prints something like <a name='af'>Afric a</a>
    >
    But if I try to simplify it, to
    print "<a name='$ct[$k]'>$continentnam e[$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 have
    tried adding extra {} and '' here and there, so far without success.
    Curly braces should work. Tried & tested:
    <?php
    $bar = 'bar';
    $foo[$bar] = 'baz';
    $foz['baz'] = 'success';
    echo "{$foz[$foo[$bar]]}";
    ?>

    So use print "<a name='$ct[$k]'>{$continentna me[$ct[$k]]}</a>\n";
    --
    Rik Wasmus
    * I'm testing several new newsreaders at the moment. Please excuse
    possible errors and weird content. *

    Comment

    • Geoff Berrow

      #3
      Re: array value as array index

      Message-ID: <op.tmppd00dqnv 3q9@misant.kabe l.utwente.nlfro m Rik
      contained the following:
      >So what is the correct way to write something like $a[$b[$c]] ? I have
      >tried adding extra {} and '' here and there, so far without success.
      >
      >Curly braces should work. Tried & tested:
      ><?php
      >$bar = 'bar';
      >$foo[$bar] = 'baz';
      >$foz['baz'] = 'success';
      >echo "{$foz[$foo[$bar]]}";
      >?>
      Or concatenation
      print "<a name='$ct[$k]'>".$continentn ame[$ct[$k]]."</a>\n";
      --
      Geoff Berrow (put thecat out to email)
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • Nick Wedd

        #4
        Re: array value as array index

        In message <d7ehr25cnngp2j 9gm4ub8cp21os0s 8vi41@4ax.com>, Geoff Berrow
        <blthecat@ckdog .co.ukwrites
        >Message-ID: <op.tmppd00dqnv 3q9@misant.kabe l.utwente.nlfro m Rik
        >contained the following:
        >
        >>So what is the correct way to write something like $a[$b[$c]] ? I have
        >>tried adding extra {} and '' here and there, so far without success.
        >>
        >>Curly braces should work. Tried & tested:
        >><?php
        >>$bar = 'bar';
        >>$foo[$bar] = 'baz';
        >>$foz['baz'] = 'success';
        >>echo "{$foz[$foo[$bar]]}";
        >>?>
        >
        >Or concatenation
        print "<a name='$ct[$k]'>".$continentn ame[$ct[$k]]."</a>\n";
        Thanks to both of you.

        I am impressed by how positive and helpful the responses in this
        newsgroup are.

        Nick
        --
        Nick Wedd nick@maproom.co .uk

        Comment

        Working...