[ create a new paste ] login | about

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

PHP, pasted on Nov 6:
<?php
    $products = array(
        'CATEGORY' =>
        array(
            0 => 'book',
            1 => 'book',
            2 => 'desk',
        ),
        'DESCRIPTION' =>
        array(
            0 => 'Bar',
            1 => 'sdfadasfdasfas',
            2 => 'Barrrr',
        ),
    );

    echo "Before:\n";
    print_r($products);

    echo "\nAfter:\n";

    $cat_to_index = '';

    foreach (array_values(array_unique($products['CATEGORY'])) as $category => $uniq_cat) {
        $keys = array_keys($products['CATEGORY'], $uniq_cat);

        if (0 < count($keys)) {
            // Occur more than once
            $cat_to_index .= join(", ", $keys) . "\n";
        }
    }

    print_r($cat_to_index);
?>


Output:
Before:
Array
(
    [CATEGORY] => Array
        (
            [0] => book
            [1] => book
            [2] => desk
        )

    [DESCRIPTION] => Array
        (
            [0] => Bar
            [1] => sdfadasfdasfas
            [2] => Barrrr
        )

)

After:
0, 1
2


Create a new paste based on this one


Comments: