I'm having a strange error which I haven't been successfully able to google a result for or find an explanation i can understand on stackOverflow. My code works fine on my local server, performing as I expect, but when I upload it, it returns the following error '*syntax error, unexpected '['in /home/maxster/max-o-matic.com/_inc/functions.php on line 59*'.
Below is line #59:
$aaPlaceholderIndex = array_keys($aaPlaceholder)[$row*4+$image]; //if associative array
Here is the whole function:
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
I'm scratching my head on this one a lot as it seems like the function is fine, it's format seems proper to me and everything is in a logical place with a good flow. I'm sure it could be better, but for me this is really good given my skill level - i'm a newb. Any thoughts on what be causing the issue with the Square brace?