0

This is my array:

Array
    (
        [0] => Array
            (
                [entity_id] => 1
                [value] => new
                [label] => New
            )
        [1] => Array
            (
                [entity_id] => 3
                [value] => pending_payment
                [label] => Pending Payment
            )
        [2] => Array
            (
                [entity_id] => 4
                [value] => pending_paypal
                [label] => Pending Paypal
            )
        [3] => Array
            (
                [entity_id] => 5
                [value] => processing
                [label] => Processing
            )
        [4] => Array
            (
                [entity_id] => 6
                [value] => complete
                [label] => Complete
            )
        [5] => Array
            (
                [entity_id] => 7
                [value] => canceled
                [label] => Canceled
            )
        [6] => Array
            (
                [entity_id] => 8
                [value] => closed
                [label] => Closed
            )
        [7] => Array
            (
                [entity_id] => 9
                [value] => holded
                [label] => Holded
            )
        [8] => Array
            (
                [entity_id] => 10
                [value] => payment_review
                [label] => Payment Review
            )
        [9] => Array
            (
                [entity_id] => 11
                [value] => new
                [label] => New
            )
        [10] => Array
            (
                [entity_id] => 13
                [value] => pending_payment
                [label] => Pending Payment
            )

UPDATE This is the result of the print_r. As you can see the array[0] with array[6] are the same. Also the array[7] with the array[1]. How can I get rid of one of them ? thx

I tried smth like this:

$input = $my_array
$temp  = $input;

foreach ( $temp as &$data ) {
    unset($data['id']);
}

$output = array_intersect_key($input, array_unique($temp));

but with no any result :( .

4
  • seems a mission to array_column and array_unique :) Can you change your output code in your question to a echo '<pre>'; print_r($array); one, please? Commented Oct 22, 2015 at 13:02
  • srry I don't get it . Can u explain me , with more details ? thx Commented Oct 22, 2015 at 13:04
  • I will try to simulate your problem and give you a solution based on the functions I've mentioned. Commented Oct 22, 2015 at 13:04
  • 1
    I did the print_r :) Commented Oct 22, 2015 at 13:08

2 Answers 2

1
$result = array();

foreach ($myArray as $array) {
    if (isset($result[$array['value']])) {
        continue;
    }
    $result[$array['value']] = $array;
}

print_r($result);
Sign up to request clarification or add additional context in comments.

Comments

0

Hey Attila this should help. Your $my_array is renamed in this example into $wholeArray. And I thought it woulf be enough to compare the labels:

$index=0;
$length = count($wholeArray);
foreach($wholeArray as $arrayElement){
    $temp = $arrayElement['label'];
    $index++;
    for($i = $index; $i < $length; $i++){
        if($wholeArray[$i]['label'] == $temp){
            unset($wholeArray[$i]);
            $length --;
        }
    }
}

If you have any questions to the code feel free to ask :)

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.