PHP 鏀寔8绉嶅熀鏈殑鏁版嵁绫诲瀷銆

鍥涚鏍囬噺绫诲瀷锛

boolean 锛堝竷灏斿瀷锛
integer 锛堟暣鍨嬶級
float 锛堟诞鐐瑰瀷, 涔熺О浣 double)
string 锛堝瓧绗︿覆锛
涓ょ澶嶅悎绫诲瀷锛

array 锛堟暟缁勶級
object 锛堝璞★級
鏈鍚庢槸涓ょ鐗规畩绫诲瀷锛

resource 锛堣祫婧愶級
NULL 锛圢ULL锛
涓轰簡纭繚浠g爜鐨勬槗璇绘э紝鏈墜鍐岃繕浠嬬粛浜嗕竴浜涗吉绫诲瀷锛

mixed
number
callback
浠ュ強浼彉閲 $....

鍙兘杩樹細璇诲埌涓浜涘叧浜庘滃弻绮惧害锛坉ouble锛夆濈被鍨嬬殑鍙傝冦傚疄闄呬笂 double 鍜 float 鏄浉鍚岀殑锛岀敱浜庝竴浜涘巻鍙茬殑鍘熷洜锛岃繖涓や釜鍚嶇О鍚屾椂瀛樺湪銆

鍙橀噺鐨勭被鍨嬮氬父涓嶆槸鐢辩▼搴忓憳璁惧畾鐨勶紝纭垏鍦拌锛屾槸鐢 PHP 鏍规嵁璇ュ彉閲忎娇鐢ㄧ殑涓婁笅鏂囧湪杩愯鏃跺喅瀹氱殑銆

Note: 濡傛灉鎯虫煡鐪嬫煇涓〃杈惧紡鐨勫煎拰绫诲瀷锛岀敤 var_dump()銆

濡傛灉鍙槸鎯冲緱鍒颁竴涓槗璇绘噦鐨勭被鍨嬬殑琛ㄨ揪鏂瑰紡鐢ㄤ簬璋冭瘯锛岀敤 gettype()銆傝鏌ョ湅鏌愪釜绫诲瀷锛屼笉瑕佺敤 gettype()锛岃岀敤 is_type 鍑芥暟銆備互涓嬫槸涓浜涜寖渚嬶細

<?php
$a_bool = TRUE;   // a boolean
$a_str  = "foo";  // a string
$a_str2 = 'foo';  // a string
$an_int = 12;     // an integer

echo gettype($a_bool); // prints out:  boolean
echo gettype($a_str);  // prints out:  string

// If this is an integer, increment it by four
if (is_int($an_int)) {
    $an_int += 4;
}

// If $bool is a string, print it out
// (does not print out anything)
if (is_string($a_bool)) {
    echo "String: $a_bool";
}
?>
濡傛灉瑕佸皢涓涓彉閲忓己鍒惰浆鎹负鏌愮被鍨嬶紝鍙互瀵瑰叾浣跨敤寮哄埗杞崲鎴栬 settype() 鍑芥暟銆

娉ㄦ剰鍙橀噺鏍规嵁鍏跺綋鏃剁殑绫诲瀷鍦ㄧ壒瀹氬満鍚堜笅浼氳〃鐜板嚭涓嶅悓鐨勫硷紝鏇村淇℃伅瑙佺被鍨嬫垙娉曘傛澶栵紝浣犺繕鍙互鍙傝 PHP 绫诲瀷姣旇緝琛ㄧ湅涓嶅悓绫诲瀷鐩镐簰姣旇緝鐨勪緥瀛愩

浠ヤ笂灏辨槸PHP绫诲瀷绠浠嬬殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=45