Removing duplicate values from an array

2

I am able to do the listing correctly, but some values are duplicated and I wanted to remove them and I can not at all ... if anyone can help me, I am very grateful.

// Creating Variable

$sector_list = $s->getSector();

// Listing

<?php foreach($sector_list as $value): ?>
    <option>
        <?php echo $value['sector']; ?>
    </option>   
<?php endforeach; ?>

The return happens correctly, but with duplicate values.

    
asked by anonymous 15.11.2018 / 17:07

1 answer

1

According to the php documentation , you can use the array_unique function.

The first parameter is the array, and the second is SORT_FLAG (not required). Below is an example:

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);

// Irá printar:
/// Array
// (
//     [a] => green
//     [0] => red
//     [1] => blue
// )

?>
    
15.11.2018 / 18:01