質問

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