3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Find id's of previous and next product in featured module $products = $this->model_catalog_product->getProducts(); $product_id = (int)$this->request->get['product_id']; $key = array_search($product_id, array_column($products, 'product_id')); $products = array_values($products); if ($key === 0) { $temp = end($products); $data['prev_product_id'] = $temp['product_id']; } else { $data['prev_product_id'] = $products[$key - 1]['product_id']; } if ($key === count($products) - 1) { $temp = reset($products); $data['next_product_id'] = $temp['product_id']; } else { $data['next_product_id'] = $products[$key + 1]['product_id']; } // Find last image of previous product $prev_product_images = $this->model_catalog_product->getProductImages($data['prev_product_id']); $prev_product_last_image = end($prev_product_images); if ($prev_product_last_image) { $data['prev_product_image'] = $this->model_tool_image->placeholder_image($prev_product_last_image['image']); } else { $data['prev_product_image'] = ''; } // Find first image of next product $next_product_images = $this->model_catalog_product->getProductImages($data['next_product_id']); $next_product_first_image = current($next_product_images); if ($next_product_first_image) { $data['next_product_image'] = $this->model_tool_image->placeholder_image($next_product_first_image['image']); } else { $data['next_product_image'] = ''; }

preferences:
54.13 ms | 402 KiB | 5 Q