unset函数

数组的unset函数测试:

'1233','h2'=>'1234','h3'=>'12344','h4'=>'11111'];
foreach ($ay as $i => $event) {
    if ($event === '1234') {
        unset($ay[$i]);
        $removed = true;
    }
}

print_r($ay);

结果是:

Array
(
    [h1] => 1233
    [h3] => 12344
    [h4] => 11111
)

可见,key也消失了

对象的unset测试

class Test{
    public $v;
}
$test=new Test();
$test->v="nihao";
$test->k="hi";
print_r($test);
unset($test->v);
print_r($test);
Test Object
(
    [v] => nihao
    [k] => hi
)
Test Object
(
    [k] => hi
)

属性也消失了

你可能感兴趣的:(unset函数)