Normal bir while döngüde gelen ths ve td fiyat değerleri, varsa virgüller nokta ile değiştirilip sırayla toplanıyor ve sonra $ths-$td farkı hesaplanıyor. Bakiyeye kadar her şey doğru, fakat çıktısı şu şekilde oluyor;
$ths=200;
$td=200;
ise ekrana Bakiye: 0 yazması gerekirken; Bakiye: 200-200 yazıyor, acaba sorun nerede?
PHP Kodu:$ths=0;
$td=0;
$ths1=$list['ths'];
if(ereg(',',$ths1))
$ths1= eregi_replace(',', '.', $ths1);
$td1=$list['td'];
if(ereg(',',$td1))
$td1= eregi_replace(',', '.', $td1);
$ths=$ths+$ths1;//tahsilat tpl
$td=$td+$td1;//tediye tpl
$bakiye=$ths-$td;
echo "Bakiye: ".$bakiye;
http://www.limonsuz.com
Sert Çocukların Yeri
Asagidaki kodu calistirdiginda ths ve td degeri string mi geliyor integer mi? Eger string'se -ki buyuk ihtimalle oyle gelecektir, degiskenleri integer'a cevirmen ya da integer cast etmen gerekli.
$ths=0;
$td=0;
$ths1=$list['ths'];
if(ereg(',',$ths1)) $ths1= eregi_replace(',', '.', $ths1);
if ($ths1 === 10) echo "String";
if ($ths1 === 10) echo "Integer";
$td1=$list['td'];
if(ereg(',',$td1)) $td1= eregi_replace(',', '.', $td1);
$ths=$ths+$ths1;//tahsilat tpl
if ($ths === 10) echo "ths - String";
if ($ths === 10) echo "ths - Integer";
$td=$td+$td1;//tediye tpl
if ($td === 10) echo "td - String";
if ($td === 10) echo "td - Integer";
$bakiye=$ths-$td;
if ($bakiye === 10) echo "bakiye - String";
if ($bakiye === 10) echo "bakiye - Integer";
echo "Bakiye: ".$bakiye;