Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

added 246 characters in body
Source Link
user1032531
  • 26.5k
  • 77
  • 249
  • 422

$post is used to simulate $_POST, and I found that $_POST['int'] is a string.

How can I tell whether $post['int'] is an integer?

The following indicates that it is not an integer.

<?php
 $post=array('int'=>(string)123);
 var_dump($post);
 echo(is_int($post['int'])?'int':'not int');
?>

EDIT. Per the documentation (http://php.net/manual/en/function.is-int.php ), is_int — Find whether the type of a variable is integer, so obviously it does exactly what it is suppose to do. Still need to tell whether the string is an integer...

$post is used to simulate $_POST, and I found that $_POST['int'] is a string.

How can I tell whether $post['int'] is an integer?

The following indicates that it is not an integer.

<?php
 $post=array('int'=>(string)123);
 var_dump($post);
 echo(is_int($post['int'])?'int':'not int');
?>

$post is used to simulate $_POST, and I found that $_POST['int'] is a string.

How can I tell whether $post['int'] is an integer?

The following indicates that it is not an integer.

<?php
 $post=array('int'=>(string)123);
 var_dump($post);
 echo(is_int($post['int'])?'int':'not int');
?>

EDIT. Per the documentation (http://php.net/manual/en/function.is-int.php ), is_int — Find whether the type of a variable is integer, so obviously it does exactly what it is suppose to do. Still need to tell whether the string is an integer...

Source Link
user1032531
  • 26.5k
  • 77
  • 249
  • 422

testing if php string is an integer

$post is used to simulate $_POST, and I found that $_POST['int'] is a string.

How can I tell whether $post['int'] is an integer?

The following indicates that it is not an integer.

<?php
 $post=array('int'=>(string)123);
 var_dump($post);
 echo(is_int($post['int'])?'int':'not int');
?>
lang-php

AltStyle によって変換されたページ (->オリジナル) /