변수형이 숫자형인지 아닌지 체크 함수 > PHP

본문 바로가기

사이트 내 전체검색

뒤로가기 PHP

변수형이 숫자형인지 아닌지 체크 함수

페이지 정보

작성자 최고관리자 작성일 21-02-09 11:56 조회 3,760 댓글 0

본문

http://php.net/manual/en/function.ctype-digit.php


 <?php
 $strings = array('1820.20', '10002', 'wsl!12');
 foreach ($strings as $testcase) {
    if (ctype_digit($testcase)) {
        echo "The string $testcase consists of all digits.\n";
    } else {
        echo "The string $testcase does not consist of all digits.\n";
    }
 }
 ?>



 <?php

 $numeric_string = '42';
 $integer        = 42;

 ctype_digit($numeric_string);  // true
 ctype_digit($integer);        // false (ASCII 42 is the * character)

 is_numeric($numeric_string);  // true
 is_numeric($integer);          // true
 ?>


 

댓글목록 0

등록된 댓글이 없습니다.

Copyright © beautipia.co.kr. All rights reserved.

contact : webmaster@beautipia.co.kr

PC 버전으로 보기