数组相同的值清晰

How can i clear one value if there is a equal version. Here my array

[1] => Array
              (
              [name] => Peter
              [city] => Texas
)

[2] => Array
              (
              [name] => Hans
              [city] => New York
)

[3] => Array
              (
              [name] => Lex
              [city] => Texas
)

So that i only get in my foreach one time Texas

<ul>
    <?php foreach ($array as $newarray) ?>
    <li><?php echo $newarray['city']; ?></li>
    <?php endforeach; ?>
</ul>

Update:

I try it this way put all cityies in an array. ($array) With print_r i got this.

Array
(
    [0] => Vorarlberg
)
Array
(
    [0] => Niederösterreich
)
Array
(
    [0] => Niederösterreich
)

After that i try <?php array_unique($array, SORT_REGULAR); ?> and with <?php echo array_unique($regionen, SORT_REGULAR); ?> i only get three thimes "Array".

Best Regards

You can use array_unique function and you have to add the SORT_REGULAR flag:

$unique_array = array_unique($array, SORT_REGULAR);

Example :

$array  = array(
array("name" => "sundar" , "city" => "madurai"), 
array("name" => "amar" , "city" => "chennai"), 
array("name" => "kumar" , "city" => "madurai"), 
array("name" => "ragu" , "city" => "trichy"), 

);  

foreach ($array as $item) {
    $cityarray[] = $item['city'];
}

 $final_array = array(); 
foreach (array_unique($cityarray) as $key => $city) {

$final_array[] =    $array[$key]; 

}
print_r($final_array); 

Use a simple array as a hash table and isset to figure out if you've been through this city before:

<?php
    $cities = array();
    foreach ($array as $newArray) {
        if (!isset($cities[$newArray['city']])) {
            $cities[$newArray['city']] = true;

            echo $newArray['city'];
        }
    }
?>

Use array_column() and array_unique() together like this:

foreach (array_unique(array_column($array, 'city')) as $city) {
    // ...
}