phpデータ型と関連関数


データ型:
スカラーデータ型:
1.ブール型

  
  
  
  
  1. $Flag = fase ; ( ) 
  2. $Flag = -1;   //true; 

2.整形

  
  
  
  
  1. $Count = 42 ;  // ;  
  2. $Count = 0123; // ; 
  3. $Count = 0x123 // ;  

3.浮動小数点型

  
  
  
  
  1. $Money = 4.56; 
  2. $Money = 4.0; 
  3. $Money = 8.7e4 //8.7 10 4  87000; 

4.文字列

  
  
  
  
  1. $str = " "
  2. $str = ' '

複合データ型
1.配列;

  
  
  
  
  1. $arrS[0] = ""
  2. $arrS[1] = ""
  3. $arrS[2] = ""; //[] Key ; ;

2.対象;

  
  
  
  
  1. class Test{  //
  2.     private $_Test;  //
  3.     function STest($Arg){  //
  4.     $this->$_Test = $Arg
  5.      } 

タイプの強制変換

  
  
  
  
  1. (array)             //  
  2. (bool) (boolean)   //  
  3. (int) (integer) 
  4. (object) 
  5. (real)or(double)(float) 
  6. (string) 
  7.  
  8.  
  9. $Str = " "
  10. echo (int)$Str;         // 0; 

タイプの自動変換

  
  
  
  
  1. <?php 
  2.  $strS = "10 string"
  3.  $intN = 10; 
  4.  // 1; 
  5.  $Re = $strS +$intN
  6.  echo "$Re<br />"
  7.  // 2; 
  8.  $Re = $intN + $strS
  9.  echo "$Re<br />"
  10.  // 3; 
  11.  $Re = $strS + $strS 
  12.  echo "$Re<br />"
  13.  
  14. /* 
  15.    20; : ,+  ; 
  16.    $strS = "string 10";  0;  
  17. */ 
  18. ?> 

関連関数:
 

  
  
  
  
  1. <?php 
  2. /* 
  3. gettype()  
  4. eg; $Flag = gettype ($var) ; 
  5.     :array;boolean;double;integer;object;resource;string;unknowntype 
  6. settype(var,string type) 
  7. ;true or flase;  
  8. */ 
  9.  
  10. // : 
  11. $str = "string 10"
  12.  $flag = gettype($strS); 
  13.  echo "$flag<br />"
  14.  
  15.  if(settype($strS,float)){ 
  16.     echo "settype "
  17.     $flag = gettype($strS); 
  18.  }else
  19.     echo "false"
  20.  } 
  21. //ps;   string   null   ; 
  22. ?> 

変数のタイプを判断する.
is_array();
is_bool();
is_float();
is_integer();
is_null();
is_numeric();
is_object();
is_resource();
is_scalar();
is_string();
ブール型を返します.すなわちtrue or false;