Home > Enterprise >  Numbering data Using Foreach php [closed]
Numbering data Using Foreach php [closed]

Time:10-06

I have data like below :

Price
0
100
200
300

if i show data by numbering using foreach, and result like below :

price
No.1 = 0
No.2 = 100
No.3 = 200
No.4 = 300

i want result like below :

price
No.2 = 100
No.3 = 200
No.4 = 300

how to display data but price 0 is not displayed, for numbers starting after price 0, using foreach php.

CodePudding user response:

Try this solution it will help in your case:

$prices = [
    0,
    100,
    200,
    300,
];


$no = 1;

echo "Prices <br>";

foreach($prices as $price)
{
    if($price != 0){
        echo "No" . $no . " = " . $price . "<br>";
    }
    $no  ;
}
  •  Tags:  
  • php
  • Related