php刪除數(shù)組某個索引值

字號:


    php可以通過unset刪除數(shù)組中的值
    舉例 如果如果沒有key的數(shù)組
    $forasp = array(1,6,9);
    var_export($forasp);
    unset($forasp[0]);
    var_export($forasp);
    //輸出結(jié)果
    array (
    0 => 1,
    1 => 6,
    2 => 9,
    )array (
    1 => 6,
    2 => 9,
    )
    如果有key的數(shù)組
    $forasp = array("site"=>"forasp","name"=>"網(wǎng)站名");
    var_export($forasp);
    unset($forasp['site']);
    var_export($forasp);
    array (
    'site' => 'forasp',
    'name' => '網(wǎng)站名',
    )array (
    'name' => '網(wǎng)站名',
    )
    這樣就可以通過php unset 刪除數(shù)組中的某個值