简体   繁体   中英

What php configuration variable disallows concatenated array indexes?

EG

if(!isset($am_states[$lot.'_-40C'])){

or

$am_states[$temp."_".$states[$i]['temperature']] = $states[$i]['temperature'];

Whenever I have arrays with concatenated string as array-keys php returns an error:

Parse error: syntax error, unexpected '.', expecting ']'

So I am assuming something is wrong with the server configuration although I am sure i changed something on my local configuration. Last time i changed the configuration was when i setup my apache/mysql/php installation

that is PHP Version 5.3.1,Apache/2.2.14,MYSQL5.1.41 (default from xampp1.7.3)

so I was using this syntaxes 7 months ago and they were working properly. It just now that they produce errors. Anyone can help?

Are you positive about the PHP version you're using? The following test (using PHP 5.3.6 (cli)) works without issue. Perhaps you could post a more complete example?

#!/usr/bin/env php
<?php

$states = array(
    array('temperature' => 40),
    array('temperature' => 50),
    array('temperature' => 60)
);

$temp = 'test';
$i = 2;

$am_states[$temp . "_" . $states[$i]['temperature']] = $states[$i]['temperature'];

var_dump($am_states);

The output of this script is:

array(1) {
  ["test_60"]=>
  int(60)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM