phpデータ型と関連関数
データ型:
スカラーデータ型:
1.ブール型
2.整形
3.浮動小数点型
4.文字列
複合データ型
1.配列;
2.対象;
タイプの強制変換
タイプの自動変換
関連関数:
変数のタイプを判断する.
is_array();
is_bool();
is_float();
is_integer();
is_null();
is_numeric();
is_object();
is_resource();
is_scalar();
is_string();
ブール型を返します.すなわちtrue or false;
スカラーデータ型:
1.ブール型
- $Flag = fase ; ( )
- $Flag = -1; //true;
2.整形
- $Count = 42 ; // ;
- $Count = 0123; // ;
- $Count = 0x123 // ;
3.浮動小数点型
- $Money = 4.56;
- $Money = 4.0;
- $Money = 8.7e4 //8.7 10 4 87000;
4.文字列
- $str = " ";
- $str = ' ';
複合データ型
1.配列;
- $arrS[0] = "";
- $arrS[1] = "";
- $arrS[2] = ""; //[] Key ; ;
2.対象;
- class Test{ //
- private $_Test; //
- function STest($Arg){ //
- $this->$_Test = $Arg;
- }
- }
タイプの強制変換
- (array) //
- (bool) (boolean) //
- (int) (integer)
- (object)
- (real)or(double)(float)
- (string)
-
- :
-
- $Str = " ";
- echo (int)$Str; // 0;
タイプの自動変換
- <?php
- $strS = "10 string";
- $intN = 10;
- // 1;
- $Re = $strS +$intN;
- echo "$Re<br />";
- // 2;
- $Re = $intN + $strS;
- echo "$Re<br />";
- // 3;
- $Re = $strS + $strS
- echo "$Re<br />";
-
- /*
- 20; : ,+ ;
- $strS = "string 10"; 0;
- */
- ?>
関連関数:
- <?php
- /*
- gettype()
- eg; $Flag = gettype ($var) ;
- :array;boolean;double;integer;object;resource;string;unknowntype
- settype(var,string type)
- ;true or flase;
- */
-
- // :
- $str = "string 10";
- $flag = gettype($strS);
- echo "$flag<br />";
-
- if(settype($strS,float)){
- echo "settype ";
- $flag = gettype($strS);
- }else{
- echo "false";
- }
- //ps; string null ;
- ?>
変数のタイプを判断する.
is_array();
is_bool();
is_float();
is_integer();
is_null();
is_numeric();
is_object();
is_resource();
is_scalar();
is_string();
ブール型を返します.すなわちtrue or false;