Warning: A non-numeric value encountered



PHP Snippet 1:

<?php

if (is_numeric($item['quantity']) && is_numeric($product['price'])) {
  $sub_total += ($item['quantity'] * $product['price']);
} else {
  // do some error handling...
}

PHP Snippet 2:

$sub_total += ((int)$item['quantity'] * (int)$product['price']);

PHP Snippet 3:

<?php 
$Page = (isset($_GET['Page']) ? $_GET['Page'] : '');
if ((int)$Page+1<=$PostPagination) {
?>
<li> <a href="Index.php?Page=<?php echo $Page+1; ?>"> &raquo;</a></li>
<?php }
?>

PHP Snippet 4:

C:\ampps\phpMyAdmin\libraries\DisplayResults.class.php

PHP Snippet 5:

// Move to the next page or to the last one
$endpos = $_SESSION['tmpval']['pos']
    + $_SESSION['tmpval']['max_rows'];

PHP Snippet 6:

$endpos = 0;
if (!empty($_SESSION['tmpval']['pos']) && is_numeric($_SESSION['tmpval']['pos'])) {
    $endpos += $_SESSION['tmpval']['pos'];
}
if (!empty($_SESSION['tmpval']['max_rows']) && is_numeric($_SESSION['tmpval']['max_rows'])) {
    $endpos += $_SESSION['tmpval']['max_rows'];
}

PHP Snippet 7:

// Move to the next page or to the last one
$endpos = $_SESSION['tmpval']['pos']
    + $_SESSION['tmpval']['max_rows'];

PHP Snippet 8:

// Move to the next page or to the last one
$endpos = (int)$_SESSION['tmpval']['pos']
    + (int)$_SESSION['tmpval']['max_rows'];

PHP Snippet 9:

$sub_total = 0;

PHP Snippet 10:

$sub_total += ($item['quantity'] * $product['price']);

PHP Snippet 11:

$total = '';
$integers = range(1, 5);

foreach($integers as $integer) {
    $total += $integer;
}

PHP Snippet 12:

<?php
$subtotal = 0; //Warning fixed
$shippingtotal = 0; //Warning fixed

$price = array($row3['price']);
$shipping = array($row3['shipping']);
$values1 = array_sum($price);
$values2 = array_sum($shipping);
(float)$subtotal += $values1; // float is irrelevant $subtotal creates warning
(float)$shippingtotal += $values2; // float is irrelevant $shippingtotal creates warning
?>

PHP Snippet 13:

$sn = 0;//increment the serial number, then add the sn to job
for($x = 0; $x<20; $x++)
{
$sn++;
$added_date = "10/10/10";
$job_title = "new job";
$salary = $sn*1000;
$cd = "27/10/2017";//the closing date
$ins = "some institution";//the institution for the vacancy 
$notes = "some notes here";//any notes about the jobs

$sn_div = "<div class='sn_div'>".$sn."</div>";
$ad_div = "<div class='ad_div'>".$added_date."</div>";
$job_div = "<div class='job_div'>".$job_title."</div>";
$salary_div = "<div class='salary_div'>".$salary."</div>";
$cd_div = "<div class='cd_div'>".$cd."</div>";//cd means closing date
$ins_div = "<div class='ins_div'>".$ins."</div>";//ins means institution
$notes_div = "<div class='notes_div'>".$notes."</div>";


/*erroneous line*/$job_no = "job"+$sn;//to create the job rows
$$job_no = "<div class='job_wrapper'>".$sn_div.$ad_div.$job_div.$salary_div.$cd_div.$ins_div.$notes_div."</div>";

echo $$job_no;//and then echo each job

}

PHP Snippet 14:

/*erroneous line*/$job_no = "job"&&$sn;//this is the new variable that will create the job rows

PHP Snippet 15:

$sub_total_price = 0; 

foreach($booking_list as $key=>$value) {
        $sub_total_price += ($price * $quantity); 
}

echo $sub_total_price;

PHP Snippet 16:

$PlannedAmount = ''; // empty string ''

if(!is_numeric($PlannedAmount)) {
           $PlannedAmount = floatval($PlannedAmount);
 }

 echo $PlannedAmount; //output = 0

PHP Snippet 17:

            "<label for='content'>Content:</label>"+
            "<textarea class='form-control col-xs-12' rows='7'cols='100' id='content' name='content'>"+$initcontent+"</textarea>'"+                 
            "</div>";

PHP Snippet 18:

$output = "<div class='from-group'>".
            "<label for='content'>Content:</label>".
            "<textarea class='form-control col-xs-12' rows='7'cols='100' id='content' name='content'>".$initcontent."</textarea>'".                 
            "</div>";

PHP Snippet 19:

 if (is_numeric($item['quantity'])) {
 if (is_numeric($product['price'])) {
    echo $item['quantity'] * $product['price'];
 } else {
    echo $item['quantity']. $product['price'];
 }
 } else {
    echo $item['quantity']. $product['price'];
 }

PHP Snippet 20:

$sub_total += ($item['quantity'] * $product['price']);

PHP Snippet 21:

$sub_total += floatval($item['quantity']) * floatval($product['price']);

PHP Snippet 22:

$subtotal = 6556.7;
$vat = number_format(0.175 * $subtotal, 2);            // 1,147.42
$transactionfee = number_format(0.02 * $subtotal, 2);  // 131.13
$total = $subtotal + $vat + $transactionfee;           // 6556.7 + 1,147.42 + 131.13 = ERROR

PHP Snippet 23:

$subtotal = 6556.7;
$vat = number_format(0.175 * $subtotal, 2, '.', '');           //1147.42
$transactionfee = number_format(0.02 * $subtotal, 2, '.', ''); //131.13
$total = $subtotal + $vat + $transactionfee;   // // 6556.7 + 1147.42 + 131.13 = 7835.25

PHP Snippet 24:

$totalPrice = ' '
$someFoo = $totalPrice + 100
// This is totally fine. And PHP will not yell about it.

PHP Snippet 25:

$totalPrice = ' '
$someFoo = $totalPrice + 100
// Error : A non-numeric value encountered.