Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php check if variable is int

// Check if variable is int
$id = "1";

if(!intval($id)){
  throw new Exception("Not Int", 404);
}
else{
	// this variable is int
}
Comment

php check if string or number

 <?php if (is_numeric(887)) { echo "Yes"; } else { echo "No"; } ?>
Comment

php check string is int

<?php
// combination of is_int and type coercion
// FALSE: 0, '0', null, ' 234.6',  234.6
// TRUE: 34185, ' 34185', '234', 2345
$mediaID =  34185;
if( is_int( $mediaID + 0) && ( $mediaID + 0 ) > 0 ){
    echo 'isint'.$mediaID;
}else{
    echo 'isNOTValidIDint';
}
?>
Comment

php check if string or number

 <?php if (is_numeric("cake")) { echo "Yes"; } else { echo "No"; } ?>
Comment

php is int

is_int(mixed $value): bool
Comment

php is_int

<?php
$values = array(23, "23", 23.5, "23.5", null, true, false);
foreach ($values as $value) {
    echo "is_int(";
    var_export($value);
    echo ") = ";
    var_dump(is_int($value));
}
?>
  
/* Output
is_int(23) = bool(true)
is_int('23') = bool(false)
is_int(23.5) = bool(false)
is_int('23.5') = bool(false)
is_int(NULL) = bool(false)
is_int(true) = bool(false)
is_int(false) = bool(false)
*/
 
Comment

php check if string is integer

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

PREVIOUS NEXT
Code Example
Php :: fillable property to allow mass assignment 
Php :: php if elseif endif 
Php :: last item coma replace and php 
Php :: php array access by key 
Php :: wordpress enqueue js 
Php :: status messages wordpress settings form 
Php :: php pdo sql server connect 
Php :: the uploaded file exceeds the upload_max_filesize directive in php.ini. wordpress 
Php :: Codeigniter 3 Get future date recocords - upcoming records from database 
Php :: url segment laravel 
Php :: Creating Laravel and Vue Project 
Php :: laravel model soft delete 
Php :: yajra laravel datatables rawcolumn 
Php :: php dirpath multiple file extensions 
Php :: create table laravel 
Php :: wordpress debug mode 
Php :: laravel convert querybuilder to string 
Php :: how to use include in php 
Php :: isset laravel 
Php :: html in php 
Php :: configuration laravel dompdf 
Php :: laravel default encryption mode 
Php :: PHP trim — Strip whitespace (or other characters) from the beginning and end of a string 
Php :: laravel tinker insert db record 
Php :: get data from csv file in php and print in table 
Php :: create symfony demo app 
Php :: last insert id mysqli 
Php :: laravel custom validation rules 
Php :: how to setup cron job for laravel queues on shared hosting 
Php :: add footer code 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =