1

i am using multi level array, arrays inside an array. and i have an index "|" and i am using this for only cloning of form elements, but when i save form, it become part of my php arrays. please let me know how can i remove it with short code.I also used PHP functions "array_walk" and "array_walk_recursive" but no success, following is display of my array of arrays

Array
(
[banner_heading] => Get Started Here!
[banner_text] => <pre id="line1">aaaa</pre>
[banner_button] => [button_blue link="#"]Buy Now[/button_blue]
[banner_media] => image
[upload_banner] => /wp-content/uploads/2013/07/videoImg.jpg
[youtube_video] => Oo3f1MaYyD8
[vimeo_video] => 24456787
[intro_heading] => Anyone Can Accept Credit Cards with Square
[intro_text] => 
[feature_content] => Array
    (
        [1] => Array
            (
                [title] => Free Secure Card Reader
                [description] => Sign up and we’ll mail you a free card reader. The reader fits right in your pocket and securely encrypts every swipe.
                [link] => #
                [icon] => /wp-content/uploads/2013/07/cardIcon.jpg
            )

        [2] => Array
            (
                [title] => Easy Setup
                [description] => Download the free Square Register app and link your bank account. No setup fees or long-term contracts. You’ll be accepting payments on your smartphone or iPad in minutes.
                [link] => #
                [icon] => /wp-content/uploads/2013/07/easyIcon.jpg
            )

        [3] => Array
            (
                [title] => Simple Pricing
                [description] => Pay just 2.75% per swipe for all major credit cards or a flat monthly $275. No other fees—so you know exactly what you pay. Square’s pricing fits businesses of all sizes.
                [link] => #
                [icon] => /wp-content/uploads/2013/07/pricingIcon.jpg
            )

        [5] => Array
            (
                [title] => 
                [description] => 
                [link] => 
                [icon] => 
            )

        [|] => Array
            (
                [title] => 
                [description] => 
                [link] => 
                [icon] => 
            )

    )
)
0

2 Answers 2

1

You can use unset:

$array; // this is your array

unset($array['feature_content']['|']);
Sign up to request clarification or add additional context in comments.

2 Comments

i can not do that because i have to do some dynamic code, i write a function to clean my all array, but is doing nothing.
function _CL( $Arr ){ if( is_array( $Arr ) ){ unset( $Arr['|'] ); foreach( $Arr as $input_ind => $input_val ){ if( is_array( $input_val ) ){ unset( $input_val['|'] ); _CL( $input_val ); } } } return $Arr; }
0

The following function can be used to recursively get the path in your array to the nodes whose keys are |. It returns an array of path nodes concatenated in a string separated colons such as $out = array('key1:key2:|', 'key3:|');:

function get_path($arr, $path = array()) {
    $out = array();
    foreach ($arr as $key => $value) {
        $full = array_merge($path, array($key));
        if ($key === '|') {
            $out[] = join(':', $full);
        } elseif (is_array($value)) {
            $out = array_merge($out, get_path($value, $full));
        }
    }
    return $out;
}

Once you get that, you can clean your array as follows:

$out = $this->get_path($arr);
if ( ! empty($out)){
    foreach ($out as $str){
        $path = explode(':', $str);
        array_pop($path);
        $nester = &$arr;
        foreach ($path as $node){
            $nester = &$nester[$node];
        }
        unset($nester['|']);
    }
}
print_r($arr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.