Mujahid Mujahid - 1 year ago 52
PHP Question

How to add a loop content to an array in php

In my current project, I need to add a loop contents to an array where I can use it later. This is my code. I tried some way but they're not working. Can anybody give a help to fix it:

for($i=0;$i<$max;$i++) {
$pid = $_SESSION['cart'][$i]['productid'];
$q = $_SESSION['cart'][$i]['qty'];
$pname = get_product_name($pid);

if($q == 0) {
} else {
$j = $i+1;

I need to add the
to an array where I should be able to use
implode(",", $pid)


Answer Source
    $j = $i+1;
echo implode(' - ',$pids);

You should be a little more clear about what your end result should be, I could be a bit more specific