Remove a array from PHP file

Viewed 43

I'm trying to remove some strings pointing to CSS files inside a PHP file. While I've mostly achieved this with PHP unlink() , the codes appear in the page source and I want to prevent this.

How can I remove some of them as in the example below?

Php File Name: css-files.php

<?php

return array(
    // Single product.
    'woo-single-prod-opt-review-images'                         => array(
        array(
            'title' => esc_html__( 'Single product review images', 'woodmart' ),
            'name'  => 'woo-single-prod-opt-review-images',
            'file'  => '/css/parts/woo-single-prod-opt-review-images',
        ),
    ),
    'woo-single-prod-el-reviews'                                => array(
        array(
            'title' => esc_html__( 'Single product reviews', 'woodmart' ),
            'name'  => 'woo-single-prod-el-reviews',
            'file'  => '/css/parts/woo-single-prod-el-reviews',
        ),
    ),
    'woo-single-prod-el-base'                                   => array(
        array(
            'title' => esc_html__( 'Single product elements base', 'woodmart' ),
            'name'  => 'woo-single-prod-el-base',
            'file'  => '/css/parts/woo-single-prod-el-base',
        ),
    ),
    'woo-single-prod-el-gallery'                                => array(
        array(
            'title' => esc_html__( 'Single product gallery', 'woodmart' ),
            'name'  => 'woo-single-prod-el-gallery',
            'file'  => '/css/parts/woo-single-prod-el-gallery',
            'rtl'   => true,
        ),
    ),
    'woo-single-prod-el-gallery-opt-thumb-left'                 => array(
        array(
            'title' => esc_html__( 'Single product gallery left', 'woodmart' ),
            'name'  => 'woo-single-prod-el-gallery-opt-thumb-left',
            'file'  => '/css/parts/woo-single-prod-el-gallery-opt-thumb-left',
            'rtl'   => true,
        ),
    ),
    'woo-single-prod-el-gallery-opt-thumb-columns'              => array(
        array(
            'title' => esc_html__( 'Single product gallery columns', 'woodmart' ),
            'name'  => 'woo-single-prod-el-gallery-opt-thumb-columns',
            'file'  => '/css/parts/woo-single-prod-el-gallery-opt-thumb-columns',
            'rtl'   => true,
        ),
    ),
);

Let's say I want to remove the following part from above strings?

    'woo-single-prod-el-base'                                   => array(
        array(
            'title' => esc_html__( 'Single product elements base', 'woodmart' ),
            'name'  => 'woo-single-prod-el-base',
            'file'  => '/css/parts/woo-single-prod-el-base',
        ),
    ),
1 Answers

Let say your are storing you returned array result into an array variable called $array, then you can use the following method to delete an array by the key

unset($array["woo-single-prod-el-gallery-opt-thumb-left"]);

Here is the complete example...

<?php

$array=array(
    // Single product.
    'woo-single-prod-opt-review-images'                         => array(
        array(
            'title' =>'Single product review images',
            'name'  => 'woo-single-prod-opt-review-images',
            'file'  => '/css/parts/woo-single-prod-opt-review-images',
        ),
    ),
    'woo-single-prod-el-reviews'                                => array(
        array(
            'title' => 'Single product reviews',
            'name'  => 'woo-single-prod-el-reviews',
            'file'  => '/css/parts/woo-single-prod-el-reviews',
        ),
    ),
    'woo-single-prod-el-base'                                   => array(
        array(
            'title' => 'Single product elements base',
            'name'  => 'woo-single-prod-el-base',
            'file'  => '/css/parts/woo-single-prod-el-base',
        ),
    ),
    'woo-single-prod-el-gallery'                                => array(
        array(
            'title' => 'Single product gallery',
            'name'  => 'woo-single-prod-el-gallery',
            'file'  => '/css/parts/woo-single-prod-el-gallery',
            'rtl'   => true,
        ),
    ),
    'woo-single-prod-el-gallery-opt-thumb-left'                 => array(
        array(
            'title' => 'Single product gallery left',
            'name'  => 'woo-single-prod-el-gallery-opt-thumb-left',
            'file'  => '/css/parts/woo-single-prod-el-gallery-opt-thumb-left',
            'rtl'   => true,
        ),
    ),
    'woo-single-prod-el-gallery-opt-thumb-columns'              => array(
        array(
            'title' => 'Single product gallery columns',
            'name'  => 'woo-single-prod-el-gallery-opt-thumb-columns',
            'file'  => '/css/parts/woo-single-prod-el-gallery-opt-thumb-columns',
            'rtl'   => true,
        ),
    ));
    
    
    
    //Array Before Delete
    echo "<pre>";
    echo print_r($array);
    echo "</pre>";
    
    //Delete Array
    unset($array["woo-single-prod-el-gallery-opt-thumb-left"]);
    
    //Array After Delete
    echo "<pre>";
    echo print_r($array);
    echo "</pre>";
    
?>
Related