I am somewhat of a programming noob, and i was stuck with an issue trying to echo out only a few items of my array instead of all the items in the array.
So what i have is a products.php file that contains my array $products, i am now trying to call this array from my index page, and i want to not only call the array, but to have the products in the array to list the last 4 products instead of all of them.
so now in my index.php i have created this code:
$total_products = count($products);
$position = 0;
$list_view_html = "";
foreach($products as $product_id => $product) {
$position = $position + 1;
if($total_product - $position < 4){
$list_view_html = $list_view_html . get_list_view_html($product_id,$product);
}
}
echo $list_view_html;
now when i save and load the webpage, i still see all the products listed and not the 4 i should be seeing.
from what i understand, i am counting the products in the array, starting the loop at 0, looping through the array and then increment up the count +1. i then am stating that if the products in the loops position is less than the 4 items i want to be shown.
i know the code might not be the best way efficiency wise, or that it has certain critiques. I appreciate all the help, but i just need to figure out why i cant get this to work.
any help is appreciated, the less condescending the better.
thanks guys