php 中輸出數(shù)據(jù)類型的函數(shù)有:1. var_dump(),打印變量的數(shù)據(jù)類型和值;2. gettype(),返回變量的數(shù)據(jù)類型字符串。
PHP 中輸出數(shù)據(jù)類型的函數(shù)
PHP 中輸出數(shù)據(jù)類型的函數(shù)主要有以下兩個(gè):
1. var_dump()
var_dump() 函數(shù)將變量的數(shù)據(jù)類型和值打印在屏幕上。它提供了有關(guān)變量類型、尺寸和值的詳細(xì)信息。
語(yǔ)法:
<code class="php">var_dump($variable);</code>
登錄后復(fù)制
例如:
<code class="php"><?php $name = "John Doe"; var_dump($name); ?></code>
登錄后復(fù)制
輸出:
<code>string(7) "John Doe"</code>
登錄后復(fù)制
2. gettype()
gettype() 函數(shù)返回變量的數(shù)據(jù)類型。它以字符串形式返回?cái)?shù)據(jù)類型。
語(yǔ)法:
<code class="php">gettype($variable);</code>
登錄后復(fù)制
例如:
<code class="php"><?php $age = 25; echo gettype($age); // 輸出:"integer" ?></code>
登錄后復(fù)制