update page now

Voting

: min(zero, eight)?
(Example: nine)

The Note You're Voting On

contact at evoweb dot fr
5 years ago
Here is a solution to make unique values keeping empty values for an array with keys :

<?php
function array_unique_kempty($array) {
    $values = array_unique($array);
    $return = array_combine(array_keys($array), array_fill(0,count($array),null));
    return array_merge($return,$values);
}

$myArray = [
    "test1" => "aaa",
    "test2" => null,
    "test3" => "aaa",
    "test4" => "bbb",
    "test5" => null,
    "test6" => "ccc",
    "test7" => "ddd",
    "test8" => "ccc"
];

echo "<pre>".print_r(array_unique_kempty($myArray),true)."</pre>";

/*
Array
(
    [test1] => aaa
    [test2] => 
    [test3] => 
    [test4] => bbb
    [test5] => 
    [test6] => ccc
    [test7] => ddd
    [test8] => 
)
*/
?>

<< Back to user notes page

To Top