0
votes
if(isset($_POST['price']))
            {
               $ret = array();
               $price=  $_POST['price'];
               array_push($ret,$price);
               $pr=count($ret);
                for($i=0; $i>$pr;$i++)
                {
                    $pri[]=$pr[$i]*$disount/100;
                    echo "<script>alert('$i'); </script>";

                }
                $nprice = implode("," , $pri);

            }
            else $nprice = '0';

when data is submitted it will get $_POST['price'] . In my code i m trying apply discount on $price.As i know discount is already set . but it is giving me error ! ) SCREAM: Error suppression ignored for Warning: implode() [function.implode]: Invalid arguments passed

3
$pr is not a array. It gives the count value. That variable stores only the integer. Not an array. - Babu
your for loop also troubled here. $i>$pr I think this loop can not run. You can't get any array result from this function. That null array was inputed on your implode function that why you get this error - Babu

3 Answers

1
votes

Your for loop is actually wrong.. Change it to

for($i=0; $i<$pr;$i++)
          //^^ <--- Do this change..

Actually it should be less than operator..

You had greater than operator and thus the condition fails , so the control flow does not go inside of your for loop, hence the $pri array obviously won't be populated and thus leading to this error.

1
votes

Initialize the $pri array before the if condition

$pri = array();

Also for the for loop, if $pr is an array the condition should be something like:

for($i=0; $i<count($pr);$i++)
0
votes

$pri is undefined here, so NULL. And NULL is an invalid argument to implode.

for($i=0; $i>$pr;$i++)

You seem to have used the wrong comparison sign (< vs. >), so the loop is never entered and $pri never set to be an array.

Fix that and for safety write $pri = array(); before the loop to initialize it.