PHP/Reflection/is string

Материал из Web эксперт
Перейти к: навигация, поиск

Using an is_ function to determine a proper data type

 
<?php 
    $unknownvar = "asdf"; 
    echo gettype ($unknownvar) . "<br />"; 
    if (is_string ($unknownvar)){ 
        echo "Is a string<br />"; 
    } 
?>



Using is_ function to determine a proper data type and then work with it

 
<?php
  $unknownvar = "Hello World";
  echo gettype ($unknownvar) . "<br />";
  if (is_string ($unknownvar)){
    echo "Is a string<br />";
  }
  $mynumber = "1.03";
  $mynumber = settype ($mynumber ,"integer");
  echo $mynumber . "<br />";
  echo (int) $mynumber;
?>