Why do I output the answer and prompt an error? Please see the code_PHP Tutorial

WBOY
Release: 2016-07-13 10:51:23
Original
1059 people have browsed it



Question
Why is the answer outputted and an error prompted? Please see the code
Solution

define(PI,3.14);

for($r = 1; $r {
$area = PI * $r * $r;

echo "r=$r, area=$area";
echo "
";
}

?>


The error message output is: Notice: Use of undefined constant PI - assumed 'PI' in D:Program FilesApache GroupApache2htdocs123.php on line 3


Reference answer
This is not an error, it is just a "note" and can be turned off
Add this
at the top of the program error_reporting(E_ALL ^ ​​E_NOTICE);
Reference answer
The second parameter in define() needs to be enclosed in single quotes, otherwise the assignment will fail, resulting in the constant not being declared, and an error will naturally occur when calling.
Reference answer
What should it pay attention to? My code is correct again!

Why do you put 3.14 in single quotes in define? Isn’t it already clear that the value of PI is 3.14?

I just learned PHP and I really don’t understand it~~
Reference answer
bool define ( string $name , mixed $value [, bool $case_insensitive ] )
No need to add quotation marks, otherwise it will become a string type. Use gettype to see it.
Reference answer
[img]http://www.111cn.cn/bbs/images/smilies/default/sweat.gif[/img]
It is recommended that you read the syntax of PHP before writing the code, define(DZ,'My name is not Big Face Cat'), the whole code means to set the value of the constant DZ to the string inside the single quotes 'I am not called Big Face Cat' Big-faced cat'. What is obvious to you may not necessarily be reasonable to the program.
Reference answer
I made a mistake. The first parameter also needs to be enclosed in single quotes. As mentioned on the 5th floor, this does not need to be considered so thoughtfully for a weakly typed language like PHP. Whether it is a string type depends on what kind of execution you are going to perform on it. Operation.
Reference answer
define(DA,'123');

define('DB','123');

define('DC',123);

echo gettype(DZ),gettype(DB),gettype(DC);

The third one is rigorous. That's right, it's because of the problem with the PHP language itself.


Copy code
Reference answer
Develop good programming habits and be taught
Reference answer
Thank you, little brother!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632578.htmlTechArticleHow to output the answer and prompt an error again? Please see the code solution define(PI,3.14); for( $r = 1; $r { $area = PI * $r * $r; echo "r=$r, area=$area"; echo " "; } ?> Wrong output...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template