[ create a new paste ] login | about

Link: http://codepad.org/BSaZ7uay    [ raw code | output | fork ]

PHP, pasted on Sep 30:
<?php
    $brand["BRAND_1"]["name"] = 'Brand Name 1';
    $brand["BRAND_1"]["list"]['SUB_BRAND_1']['name'] = 'Headline Subbrand 1';
    $brand["BRAND_1"]["list"]['SUB_BRAND_1']['text'] = 'text for Subbrand 1';
    $brand["BRAND_1"]["list"]['SUB_BRAND_2']['name'] = 'Headline Subbrand 2';
    $brand["BRAND_1"]["list"]['SUB_BRAND_2']['text'] = 'text for Subbrand 2';

    $brand["BRAND_2"]["name"] = 'Brand Name 2';
    $brand["BRAND_2"]["list"]['SUB_BRAND_1']['name'] = 'Headline Subbrand 1';
    $brand["BRAND_2"]["list"]['SUB_BRAND_1']['text'] = 'text for Subbrand 1';


    $order[1] = 'BRAND_1::SUB_BRAND_1';
    $order[2] = 'BRAND_1::SUB_BRAND_2';
    $order[3] = 'BRAND_2::SUB_BRAND_1';

    // for testing
    $orderId = 2;

    // get the brand and sub_brand
    $part = explode("::", $order[$orderId]); 

    // set the new brand list
    $newBrand[$part[0]]['name'] = $brand[$part[0]]['name'];
    $newBrand[$part[0]]['list'][$part[1]] = $brand[$part[0]]['list'][$part[1]];

    // unset the brand which should be first of the main brand array
    unset($brand[$part[0]]['list'][$part[1]]);

    // if there was only one list unset the whole brand
    if( count($brand[$part[0]]['list']) < 1 ) {
        unset( $brand[$part[0]] );
    }

echo "first item";
print_r( $newBrand );

echo "needs to get combined with this item";
print_r( $brand );


?>


Output:
first itemArray
(
    [BRAND_1] => Array
        (
            [name] => Brand Name 1
            [list] => Array
                (
                    [SUB_BRAND_2] => Array
                        (
                            [name] => Headline Subbrand 2
                            [text] => text for Subbrand 2
                        )

                )

        )

)
needs to get combined with this itemArray
(
    [BRAND_1] => Array
        (
            [name] => Brand Name 1
            [list] => Array
                (
                    [SUB_BRAND_1] => Array
                        (
                            [name] => Headline Subbrand 1
                            [text] => text for Subbrand 1
                        )

                )

        )

    [BRAND_2] => Array
        (
            [name] => Brand Name 2
            [list] => Array
                (
                    [SUB_BRAND_1] => Array
                        (
                            [name] => Headline Subbrand 1
                            [text] => text for Subbrand 1
                        )

                )

        )

)


Create a new paste based on this one


Comments: