0

3 and learning from a book (php a begginers guide, vikram vaswani) and am following his guides and have entered his code

$whoami="sarah";
echo gettype ($whoami);

$whoami=99.8;
echo gettype ($whoami);

unset ($whoami);
echo gettype ($whoami);

the error i am getting is this

Undefined variable: whoami in C:\inetpub\wwwroot\etc..

I was hoping someone could explain why? also, off topic but if anyone knows if this book is anygood or not for a complete begginer could they recommend a better one as i have had quite a few errors when entering code ?

thankyou

4

2 回答 2

3

基本上,您使用unset()来销毁变量。

但有一些微妙之处:

unset()销毁指定的变量。

函数内部unset()的行为可能因您尝试销毁的变量类型而异。

如果一个全局变量在函数内部是unset(),则只有局部变量被销毁。调用环境中的变量将保留与调用unset()之前相同的值。

资料来源:unset() 文档

于 2013-03-22T12:03:22.877 回答
2

好朋友,在 php 中取消设置是为了销毁您放入变量中的任何内容 unset 和 delo 为什么会发生错误,因为他销毁了变量,而当您尝试使用她下面的代码时,她已经不复存在了。

于 2013-03-22T12:01:01.370 回答