LoginSignup
0
0

More than 1 year has passed since last update.

PHP unset 変数削除

Posted at

用途

定義した変数を削除したい時に使う。
配列から指定した値を削除したい時に使う。
処理の終わりに毎回変数をリセットしたい時などにも使える。

使用方法

変数削除
$hoge = "ほげほげ";
unset($hoge); // $hogeという変数を削除

var_dump(isset($hoge)); // bool(false)

isssetの結果、falseが返ってきているから削除できている。

配列から指定した値を削除
$hoge = array(0, 1, 2, 3, 4, 5);
unset($hoge[1]); // 配列の「1」が削除される

print_r($hoge);
// 結果
[0] => 0
[2] => 2
[3] => 3
[4] => 4

※配列の場合は、削除したいインデックスを指定する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0