If I set

$myVar = "yay";
die($myVar);

that echos out yay, and kills the script.

However, if I set

$myVar = 2;
die($myVar);

nothing echos.

Why is that?

Cheers guys.

有帮助吗?

解决方案 2

If you really want to print an integer then simply cast it as a string

<?php
  $var = 1;
  # exit() or die()
  exit("".$var);
?>

其他提示

Directly from the PHP Manual, die() is the same as exit(), and exit($status) says this:

If status is a string, this function prints the status just before exiting.

If status is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top