Syntax not allowed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Stearns

    #1

    Syntax not allowed

    The following is not allowed (simplified for this forum): but it seems
    reasonable to me. Could some one explain mw lack of insight?

    $t = (array(1=>"Sold ", 3=>"Transit"))[$location_id];

    Parse error: parse error, unexpected '[' in
    /var/www/html/GEM-is/batchJobs/sales.php on line 183
  • Chung Leong

    #2
    Re: Syntax not allowed

    The parser can't handle such syntax, that's all.

    Comment

    • Manifest Interactive

      #3
      Re: Syntax not allowed

      Greetings,

      This is the standard syntax to build a PHP array:

      $myArray = array('index1' => 'val1', 'index2' => 'val2', 'index3' =>
      'val3');

      To create a multidimensiona l array you could use something like this:

      $myArray = array("A" => array("a", "b", "c" => array("x")), "B" =>
      "y");

      Not sure if this is close to what you are looking for

      - Peter Schmalfeldt
      Manifest Interactive

      Comment

      • Tim Roberts

        #4
        Re: Syntax not allowed

        "Manifest Interactive" <manifestintera ctive@gmail.com > wrote:
        [color=blue]
        >Greetings,
        >
        >This is the standard syntax to build a PHP array:
        >
        >$myArray = array('index1' => 'val1', 'index2' => 'val2', 'index3' =>
        >'val3');
        >
        >To create a multidimensiona l array you could use something like this:
        >
        >$myArray = array("A" => array("a", "b", "c" => array("x")), "B" =>
        >"y");
        >
        >Not sure if this is close to what you are looking for[/color]

        Not at all. He was trying to create a temporary array and reference an
        element of it without saving to a variable. I, also, am surprised this
        doesn't work.
        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        Working...