0

Well the problem is that I wrote a code that's avoiding showing of duplicate data. On my local machine it works perfectly but on host I am getting a following error:

Syntax error, unexpected '[' in /home/eplus/public_html/vqmod/vqcache/vq2-catalog_view_theme_default_template_product_product.tpl on line 481

Here is the code where error occurs

if ($pr_id[$i] == 0) {
   break;
   echo 'h1' . "Нет похожих продуктов";
}

if ($pr_id[$i] != array_unique($pr_id)[$i]) {    // Error on this line
   $product_fee = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product_to_category` WHERE `category_id`='".$feed_id."' AND NOT `product_id` = '".$products_id."'  GROUP BY `product_id` ORDER BY RAND() LIMIT 0,10");

   $pr_id[$i] = $product_fee->row['product_id'];

   continue;
}

How can I avoid this? As for CMS I am currently using OpenCart.

1 Answer 1

3

Array dereferencing is supported only in PHP version 5.4 and above.
It is when you use bracket access directly after a function that returns an array: array_unique($array)[0].

Read more: PHP 5.4: New features

I would advise you to create the array with unique items before the if clause:

$pr_unique = array_unique($pr_id);

if ($pr_id[$i] != $pr_unique[$i]) {
    ....
}
Sign up to request clarification or add additional context in comments.

3 Comments

What could be a substitute of this function?
Oh wow! I did not know this! I was hoping PHP would implement that capability someday!
Thank you a lot guys! The code provided above works just as expected!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.