我有一个奇怪的错误,我没有成功地谷歌搜索结果或找到我可以在stackOverflow上理解的解释。我的代码在我的本地服务器上工作正常,按照我的预期执行,但是当我上传它时,它会返回以下错误'* syntax error,unexpected'['in /home/maxster/max-o-matic.com/_inc/ functions.php在第59行*'。
以下是第59行:
$aaPlaceholderIndex = array_keys($aaPlaceholder)[$row*4+$image]; //if associative array
这是整个功能:
function PrintFolio($aaPlaceholder)
{
//print out X number rows, four items at time
$itemsCount = sizeof($aaPlaceholder);//get size of array
$height = (int)ceil(sizeof($aaPlaceholder)/4);//get size of array divided by 4
//loop through array of X items, for each group of 4 print as a row
for($row = 0; $row < $height; $row++) //looping through the rows
{
echo '<div class="row flush">'; //open div
for($image = 0; $image < 4; $image++) //each row is composed of 4 images
{
//$aaPlaceholderIndex = $row*4+$image; //if indexed array
$aaPlaceholderIndex = array_keys($aaPlaceholder)[$row*4+$image]; //if associative array
if( $aaPlaceholderIndex <= $itemsCount ) {
printf(TEMPLATE_PORTFOLIO, $aaPlaceholderIndex, $aaPlaceholder[$aaPlaceholderIndex]);
//$template = '<div class="3u"><a href="_img/fulls/%1$s" class="image full"><img src="_img/thumbs/%1$s" alt="" title="%2$s" /></a></div>';
}
}
echo '</div>'; //end div group of 4
}//end loop
}//end function
我对这个问题很感兴趣,因为看起来功能很好,它的格式对我来说似乎很合适,而且一切都在合理的位置,流畅。我相信它可能会更好,但对我而言,鉴于我的技术水平,这真的很棒 - 我是个新手。有关Square支撑问题的原因有什么想法吗?
答案 0 :(得分:5)
直到PHP 5.4才引入数组解除引用。您的生产版本没有运行PHP 5.4,但您的本地环境是。所以:
$aaPlaceholderIndex = array_keys($aaPlaceholder)[$row*4+$image]; //if associative array
变为:
$tempArray = array_keys($aaPlaceholder); //if associative array
$aaPlaceholderIndex = $tempArray[$row*4+$image]