Michael
Michael

Reputation: 39

Unsetting an array in php

I have a file called layout.php which contains

<?php
$arrLayout = array(
    "section1" => array(

        "wXBMCLibrary" => array(
            "title" => "XBMC Library",
            "display" => ""
        ),
        "wRecentMovies" => array(
            "title" => "Recent Movies",
            "display" => ""
        ),
        "wRecentTV" => array(
            "title" => "Recent TV",
            "display" => ""
        )
    )
    );
?>

What I would like to be able to do is remove any part, for example if I say remove wXBMCLibrary it must remove all of the below

 "wXBMCLibrary" => array(
        "title" => "XBMC Library",
        "display" => ""
    ),

Is this at all possible? Would you be able to unset the whole piece? What would the coding be? Regards

Upvotes: 1

Views: 70

Answers (2)

Robert
Robert

Reputation: 8767

This is completely possible through the usage of unset() within PHP. The unset() function will remove the item that you specify, so if you specify unset($arrLayout['section1']['wXBMCLibrary']); then that will remove the array with the index of 'wXBMCLibrary'.

PHP - Unset() function

Upvotes: 0

Karoly Horvath
Karoly Horvath

Reputation: 96266

unset($arrLayout['section1']['wXBMCLibrary']);

Upvotes: 1

Related Questions