Data Type Issues

  • Convert to integer: intval($string)
  • Check integer: is_int($int)
    note:The parameter must be "Integer" already.
  • Check numeric: is_numeric($str)
    Note: is_numeric('0123') will return true;
  • Force convert: (int)"abcd" == 0 will be "true"!!
  • 0 == NULL will be true!!
  • "==" and "==="
    $str = "field123"
    $pos = strpos($str, "field"); (0)
    $pos == false -> true (convert 0 automatically)
    $pos === false -> false

 

  • Get integer value: intval($string)
    intval(NULL) = 0
    intval('') = 0
    intval('rex') = 0
    intval(-1) = -1
  • isset:
    isset(NULL) = false
    isset('') = error
    isset('rex') = error
    isset($row) = true / false

One thought on “Data Type Issues

  1. gary

    Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your
    weblog? My blog site is in the very same area of interest as yours and my users would
    certainly benefit from a lot of the information you
    present here. Please let me know if this
    alright with you. Cheers!

Comments are closed.