是否可以区分参数是字符串还是数字?在PHP中


Is it possible to differentiate whether an argument is a string or number? in PHP

假设这个

function Args($a) {
  if (/*HOW*/) {
    echo "the argument is a pure number";
  } else {
    echo "the argument is a string";
  }
}
Args(4); -> the argument is a pure number
Args("4"); -> the argument is a string

根据函数和示例,我如何才能获得差异,根据类型参数?

使用内置函数is_int($value)is_string($value)

is_int的手册在这里,此处的is_string手册

使用内置的gettype()函数。

function Args($a) {
    $type=gettype($a);
    echo "the argument is a ".$type;
}