|
 |
|
รบกวนทีครับ..คำสั่งแปลง char เป็น int ภาษา PHP........ |
|
 |
|
|
 |
 |
|
ใช้คำสั่ง Settype ครับ
รูปแบบ
Code (PHP)
<?php
settype('ข้อความ', "integer");
?>
|
 |
 |
 |
 |
Date :
2010-11-11 15:50:37 |
By :
adaaugusta |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ว่าแต่ PHP มี Type ด้วยหรือครับ $Var ก็น่าจะ บวกได้เลย!
|
 |
 |
 |
 |
Date :
2010-11-11 16:08:49 |
By :
สุรชัย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
settype('ข้อความ', "integer"); คือการกำหนด ชนิดข้อมูลใหม่ ให้กับตัวแปร   
|
 |
 |
 |
 |
Date :
2010-11-11 16:30:55 |
By :
penpimonmink |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าจำนวนเต็มให้ใช้ $intNew = (int)$string;
|
 |
 |
 |
 |
Date :
2010-11-11 16:35:01 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โดยปกติน่ะครับ PHP มันจะยืดดดหยุ่นมากเลยทีเดียว
มันจะรับรู้ด้วยตัวมันเอง ว่าคำนวณได้ หรือไม่ได้
สมมุติ
00001 ไม่รู้ว่าเป็น type ไหน
ถ้าเราทำ 00001+5 มันก็มองเป็น int ให้ครับ สามารถคำนวณได้
แต่ถ้าอยากรู้ว่า จริงๆแล้ว ข้อมูลเป็นชนิดไหน
ให้ใช้ gettype ครับ มันจะบอกว่า ข้อมูลเป็น int , char , float etc....
แต่ถ้าอยากเปลี่ยนชนิดข้อมูล เป็นที่ต้องการก็ใช้ settype แบบที่บอกนะครับ
จำไว้สั้นๆ get = แสดง , set = กำหนด
|
 |
 |
 |
 |
Date :
2010-11-11 17:12:58 |
By :
adaaugusta |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทฤษฎีแน่นจริงๆ
ลูกทุ่งอย่างเราต้องมาลักจำไปใช้
|
 |
 |
 |
 |
Date :
2010-11-11 18:26:23 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
222
|
 |
 |
 |
 |
Date :
2013-06-14 11:00:55 |
By :
jjj |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|