php

2020.09.18 09:45

숫자 체크

  • 관리자 2020.09.18 인기
  • 7,514
    0
$tests = array(
  "42",
  1337,
  0x539,
  02471,
  0b10100111001,
  1337e0,
  "not numeric",
  array(),
  9.1,
  null
 );

 foreach ($tests as $element) {
  if (is_numeric($element)) {
  echo var_export($element, true) . " is numeric", PHP_EOL;
  } else {
  echo var_export($element, true) . " is NOT numeric", PHP_EOL;
  }
 }
 ------------------------------------------------------------
 ctype_digit() - Check for numeric character(s)
 is_bool() - Finds out whether a variable is a boolean
 is_null() - Finds whether a variable is NULL
 is_float() - Finds whether the type of a variable is float
 is_int() - Find whether the type of a variable is integer
 is_string() - Find whether the type of a variable is string
 is_object() - Finds whether a variable is an object
 is_array() - Finds whether a variable is an array
  • 공유링크 복사

    댓글목록

    등록된 댓글이 없습니다.