问题描述:

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

网友答案:

Basically, you use unset() to destroy a variable.

But there are a few subtleties:

unset() destroys the specified variables.

The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy.

If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.

Source: the unset() documentation.

网友答案:

Good day friend, unset in php is to destroy anything in your case you put inside a variable unset and delo why the error happened because he destroyed the variable and when you try to use the code below her she was no more.

相关阅读:
Top