PHP:Hapus digit didari belakang

Misalkan kita punya permasalahan memotong angka :

1310 menjadi 13

67891 menjadi 678

Yaitu menghapus 2 digit terakhir dari belakang.

Script PHP


function getPotongAngka($angka){
$angka = (int)$angka;
$i_str = (string)$angka;
$angkax = substr($i_str, 0, -2);
return (int)$angkax;

$total = getPotongAngka(1310);
$total2 = getPotongAngka(44123);
echo “<br>Angka1 : “.$total;
echo “<br>Angka2 : “.$total2;

Hasilnya :

Angka1 : 13
Angka2 : 441


About blackphp

All about programming php, ajax, jquery, mysql, etc, tips n trick. Now, i'm concern in php programming with codeigniter framework n also training my design skill with photoshop or corel... wish me luck! ('o')

Posted on January 10, 2012, in PHP and tagged , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: