PHP 支援 8 種原始資料類型。
四種標量類型:(標量類型即為基本類型)
兩種複合類型:
最後是兩種特殊類型:
resource(資源)
NULL(無類型)
resource(確切地說,是由PHP 根據該變數使用的上下文在運行時決定的。
如果想查看某個表達式的值和型別,用 var_dump() 函數。
如果只是想得到一個容易理解的類型的表達方式用於調試,用 gettype() 函數。要查看某個類型,不要用 gettype(),而用 is_type 函數。
<code><span><span><?php </span><span>$a_bool</span> = <span>TRUE</span>; <span>// a boolean</span><span>$a_str</span> = <span>"foo"</span>; <span>// a string</span><span>$a_str2</span> = <span>'foo'</span>; <span>// a string</span><span>$an_int</span> = <span>12</span>; <span>// an integer</span><span>$a_float</span> = <span>3.14</span>; <span>// a float(double)</span><span>echo</span> gettype(<span>$a_bool</span>).<span>"<br>"</span>; <span>// prints out: boolean</span><span>echo</span> gettype(<span>$a_str</span>).<span>"<br>"</span>; <span>// prints out: string</span><span>echo</span> gettype(<span>$an_int</span>).<span>"<br>"</span>; <span>// prints out: integer</span><span>echo</span> gettype(<span>$a_float</span>).<span>"<br>"</span>; <span>// prints out: double</span><span>// If this is an integer, increment it by four</span><span>if</span> (is_int(<span>$an_int</span>)) { <span>echo</span><span>"an_int = "</span>.<span>$an_int</span>.<span>"<br>"</span>; <span>$an_int</span> += <span>4</span>; <span>echo</span><span>"an_int = "</span>.<span>$an_int</span>.<span>"<br>"</span>; } <span>// If $bool is a string, print it out</span><span>// (does not print out anything)</span><span>if</span> (is_string(<span>$a_str</span>)) { <span>echo</span><span>"String: $a_str"</span>.<span>"<br>"</span>; } <span>echo</span> var_dump(<span>$a_float</span>, <span>$a_bool</span>, <span>$a_str</span>, <span>$an_int</span>); <span>?></span></span></span></code>輸出:
<code>boolean <span>string</span> integer <span>double</span> an_int = <span>12</span> an_int = <span>16</span> String: foo <span>float</span>(<span>3.14</span>) <span>bool</span>(<span>true</span>) <span>string</span>(<span>3</span>) <span>"foo"</span><span>int</span>(<span>16</span>)</code>php手冊中對gettype()的解釋(請放大查看?):
類型的具體使用,請參考這裡PHP的官方手冊,我
🎜🎜拋磚引玉。 🎜🎜').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i 🎜').text(i)); }; $numbering.fadeIn(1700); }); }); 🎜 🎜 以上就介紹了PHP學習(4)-資料類型,包含了方面的內容,希望對PHP教程有興趣的朋友有所幫助。 🎜 🎜 🎜