常用的数据类型有字符串型、浮点型(单精度浮点型float、双精度浮点型double)、整形、布尔型
1 其他类型转化为整型
1.1 字符串型转化为整型
1.1.1 如果字符串全部为数字,则直接全部转换为整型,如果有小数点则会去除小数点后面的内容,如 '12' 跟 '12.3' 转换为整型后都为12
1.1.2 如果字符串以字母开头则不管中间或后面有多少数字或小数点,转换为整形后都为0。如'ab12.3c'转换为整型后为0
1.1.3 如果以数字开头,则会去掉数字后面的字符,如果有小数点则去除小数点后面的。如 '123.4abc' 、 '123abc' 转换为整形后都为123
1.2 浮点型转化为整型
1.2.1 如果浮点数含有小数点则去掉小数点后面的字符,如果没有则直接变为整型 。如:浮点数 12.6 转换为整形后为12
1.3 布尔型转化为整型
1.3.1 布尔型转换为整型时,true会转换为 1 false 会转换为 0其中NULL转换为整型后为0 所以如果要判断 if(NULL == 0){echo "NULL等于0";} 是会返回NULL等于0的
2 其他类型转化为字符串型
2.1 整型、浮点型转换为字符串型是直接在数字上加引号 如12 12.3 转换为字符串后为 "12" "12.3"
2.2 布尔型转换为字符串是,true会转换成字符串"1",false 跟NULL转换为字符串结果为空字符串,不会有输出
3 其他类型转化为浮点型
3.1 整型直接转化为浮点型,数值不变,字符串转换为浮点型跟字符串转换为整型基本上是一样的,只不过是当字符串之间有小数点时,小数点会保存。如 “12.3abc” 转换之后为 12.3 其他形式的是一样的方法
3.2 布尔型转换为浮点型是,true会转换成浮点型 1 ,false 跟NULL转换为浮点型结果为0
4 其他类型转化为布尔型
4.1 空字符串转换为 布尔型为FALSE,非空为TRUE;整型跟浮点型的0转换为布尔型为FALSE,其他为TRUE
4.2 NULL转换为布尔型后结果为FALSE
PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有:
•(int)、(integer):转换成整形
•(float)、(double)、(real):转换成浮点型
•(string):转换成字符串
•(bool)、(boolean):转换成布尔类型
•(array):转换成数组
•(object):转换成对象
PHP数据类型有三种转换方式:
•在要转换的变量之前加上用括号括起来的目标类型
•使用3个具体类型的转换函数,intval()、floatval()、strval()
•使用通用类型转换函数settype(mixed var,string type)
第一种转换方式,(int) (bool) (float) (string) (array) (object),代码如下:
- <?php
- $num1=3.14;
- $num2=(int)$num1;
- var_dump($num1); //输出float(3.14)
- var_dump($num2); //输出int(3)
- ?>
第二种转换方式,intval() floatval() strval(),代码如下:
- <?php
- $str=”123.9abc”;
- $int=intval($str); //转换后数值:123
- $float=floatval($str); //转换后数值:123.9
- $str=strval($float); //转换后字符串:”123.9″
- ?>
第三种转换方式,settype();代码如下:
- <?php
- $num4=12.8;
- $flg=settype($num4,”int”);
- var_dump($flg); //输出bool(true)
- var_dump($num4); //输出int(12)
- ?>
波比源码 » php数据类型转换学习笔记
levaquin usa levaquin cost
avodart 0.5mg for sale order zofran online ondansetron 8mg ca
brand aldactone 25mg propecia for sale oral diflucan 100mg
sildenafil 50mg canada robaxin medication robaxin sale
order lamotrigine pills buy retin for sale tretinoin over the counter
accutane pills accutane 40mg ca buy azithromycin without prescription
levitra or cialis cheap medication online purchase viagra generic
brand deltasone 5mg generic cialis soft tabs 20mg viagra 50mg for sale
order ramipril 5mg pills irbesartan 150mg ca astelin cheap
buy clonidine 0.1mg generic clonidine tablet order spiriva 9 mcg generic
purchase buspirone generic order dilantin 100 mg online oxybutynin 5mg ca
order revia 50 mg for sale albendazole 400mg us order generic abilify
order fluvoxamine 100mg sale order fluvoxamine 50mg for sale order glucotrol pills
brand isotretinoin cheap deltasone 5mg prednisone over the counter
buy nootropil 800mg online purchase sildenafil sale order viagra 50mg without prescription
cheap azithromycin 500mg azithromycin 500mg pill oral gabapentin 800mg
purchase chloroquine chloroquine pills olumiant 2mg for sale
purchase zyprexa pills bystolic 5mg generic diovan 80mg sale
buy zyvox without prescription free blackjack online online roulette game
levitra 10mg over the counter lyrica 75mg cheap buy medrol 8mg online
clomid 100mg drug clomiphene 100mg oral casino play
buy triamcinolone pill loratadine brand purchase desloratadine for sale
buy priligy 30mg sale purchase levothyroxine generic order synthroid 150mcg sale
buy cialis 20mg sale tadalafil 20mg brand cheap generic viagra
allopurinol 300mg usa order zetia without prescription order zetia online
global poker online online blackjack with friends big fish casino online
tamsulosin 0.2mg over the counter tamsulosin over the counter buy generic spironolactone 100mg
simvastatin order online purchase simvastatin online buy proscar 1mg for sale
order viagra 100mg buy viagra 50mg generic order cialis 10mg without prescription
order ceftin pill order robaxin online robaxin 500mg canada
best online casino real money casino gambling cialis coupon cvs
affordable thesis writing best essay writing websites stromectol sales
deltasone 10mg for sale order amoxil pill buy amoxil 500mg generic
slots real money stromectol tablets for humans modafinil 100mg generic
buy generic lasix 40mg buy furosemide 40mg online cheap hydroxychloroquine sale
sildenafil drug fildena 50mg without prescription purchase rhinocort online cheap
retin gel usa order retin online order avanafil 200mg for sale
biaxin pills buy clarithromycin 250mg online order meclizine 25mg
cheap cialis generic Overnight delivery cialis cialis tadalafil 40mg
purchase tadalafil online online slots real money usa poker online play
stromectol tablets for sale order stromectol generic buy dapsone 100mg for sale
real money blackjack play roulette online real money poker online for money
purchase adalat without prescription fexofenadine 180mg sale fexofenadine 120mg oral
money games online slots real money usa poker online sites
order ramipril 10mg without prescription arcoxia pill purchase etoricoxib generic
pay for assignment leflunomide cost purchase azulfidine without prescription
diamox 250 mg us order azathioprine 50mg sale buy imuran 25mg pills
lanoxin online order telmisartan 20mg pills order molnunat 200 mg online cheap
order amoxicillin buy stromectol 12mg generic ivermectin cream canada cost
purchase tadalafil sale order generic plavix 150mg cheap trimox
fenofibrate oral tricor cost sildenafil 100mg generic
minocin 50mg generic order gabapentin 600mg purchase hytrin without prescription
brand tadalafil 20mg buy ed medications natural ed pills
glucophage 500mg for sale tamoxifen pills order nolvadex 10mg for sale
order accutane without prescription deltasone usa order ampicillin
order zofran 4mg online cheap amoxicillin pills bactrim 960mg usa
buy accutane 40mg online cheap order absorica for sale zithromax ca
albuterol 4mg canada buy levothroid online buy amoxiclav for sale
order azathioprine 50mg pill order naprosyn 250mg generic naproxen 500mg uk
omnicef uk lansoprazole 30mg oral protonix 20mg canada
simvastatin 10mg cheap zocor order online sildenafil 150 mg
viagra sildenafil 50mg sildenafil 20 mg generic cialis 10mg
levaquin 500mg for sale ursodiol 300mg generic zyban price
order cenforce 100mg generic cheap glycomet glycomet 500mg cost
order lipitor 10mg pills order sildenafil 100mg for sale sildenafil generic
tadalafil 5mg price buy ed medication online best over the counter ed pills
where to buy provigil without a prescription promethazine for sale online buy prednisone 20mg pill
order accutane 10mg online cheap buy amoxicillin 1000mg for sale buy zithromax pill
gabapentin 100mg usa gabapentin 800mg price order doxycycline 200mg generic
prednisolone uk purchase gabapentin pill buy furosemide without prescription diuretic
ventolin 2mg brand ventolin online order buy synthroid pill
order pregabalin 75mg dapoxetine 90mg sale purchase priligy sale
buy generic orlistat 120mg order acyclovir 400mg online cheap zyloprim 100mg ca
brand cozaar 25mg esomeprazole 40mg for sale topiramate without prescription
zantac over the counter celebrex cost order celecoxib 100mg pill
flomax 0.4mg oral order aldactone aldactone 25mg tablet
brand cymbalta 40mg nootropil cost buy nootropil 800mg generic
order generic betamethasone 20gm order betamethasone 20gm for sale sporanox price
buy nateglinide 120mg generic order nateglinide 120mg without prescription purchase candesartan sale
nebivolol uk buy nebivolol 20mg pills order clozapine online
duricef 250mg over the counter buy generic duricef buy proscar online cheap
buy generic estradiol for sale buy prazosin 2mg sale order minipress 1mg online
metronidazole online septra usa cephalexin 500mg without prescription
nolvadex order buy budesonide paypal buy ceftin 250mg online
indomethacin brand buy generic indocin for sale cost cefixime 100mg
careprost online bimatoprost usa desyrel 50mg pills
buy catapres no prescription order spiriva 9mcg buy tiotropium bromide 9 mcg online cheap
ramipril 10mg usa arcoxia 120mg sale etoricoxib canada
buy levitra generic order tizanidine 2mg plaquenil over the counter
oral clobetasol buy clobetasol for sale brand cordarone 200mg
buy lanoxin 250 mg generic order generic micardis molnupiravir 200 mg brand