Use the defined function
defined(String constants_name)
If the constant exists, return bool(true)
If it does not exist, return bool(false)
<?php define("name",unique); $p = "name"; $is1 = defined($p); $is2 = defined("p2"); var_dump($is1); var_dump($is2); ?>
The above introduces how PHP determines whether a constant is defined? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.