php gets the status of a variable

WBOY
Release: 2016-07-25 08:44:11
Original
840 people have browsed it

isset()
isset()-Check whether the variable is set
Grammar:
bool isset (mixed $var [,mixed $var [,$....]])
Description:
Returns true if var exists, false otherwise.
Note:
If the variable has been unset() before or is set to null, isset() will return false.

unset()
unset()- Destroy the given variable
void unset (mixed $var [,mixed $...])
The behavior of the unset() function varies depending on the type of the given variable. If you unset() a global variable in a function, only the local variable is destroyed, and the variables in the calling environment will retain the same value before calling unset().
If you want to unset() a global variable, you can use the $GLOBALS array:
unset($GLOBALS['bar']);
If you unset() a variable passed by reference, only the local variable is destroyed, and the variables in the calling environment will retain the same value before calling unset().

  1. function foo(&$bar) {
  2. unset($bar);
  3. $bar = 'blah';
  4. }
  5. $bar = 'something';
  6. echo "$barn";
  7. foo($bar);
  8. echo "$barn";
  9. ?>
Copy code

The above routine will output:

  1. something
  2. something
Copy code

If you unset() a static variable in a function, the static variable will be destroyed before inside the function. However, when this function is called again, this static variable will be restored to the value it had before it was last destroyed.

  1. function foo() {
  2. static $bar;
  3. $bar++;
  4. echo "Before unset: $bar, ";
  5. unset($bar);
  6. $bar = 23;
  7. echo " after unset: $barn";
  8. }
  9. foo();
  10. foo();
  11. foo();
  12. ?>
Copy code

The above routine will output:

  1. Before unset: 1, after unset: 23
  2. Before unset: 2, after unset: 23
  3. Before unset: 3, after unset: 23
Copy code

empty()
empty()-checks if a variable is empty
Grammar:
bool empty (mixed $var)
Description:
If $var is a non-empty or non-zero value, empty() returns false. For example, "", 0, "0", null, false, array(), var $var, and objects without any attributes will be considered empty.

php


Related labels:
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