0

probably an already discussed topic, but in Php I did not found an answer Is there a simpler way to realize in what follows:

$a = array("hello","hello","Hello","world","worlD");
$p=array();
foreach( $a as $v ){
    $p[strtolower($v)] = "";
}
print_r($p);

keep one single element, in small-case, for the array

3
  • Use a conditional statement or something like what Yoshi just answered. Commented Jun 8, 2012 at 14:05
  • @sephoy he wants to remove duplicates from his array. Commented Jun 8, 2012 at 14:05
  • @dynamic: i see, so yoshi's answer can do this Commented Jun 8, 2012 at 14:06

2 Answers 2

3

something like:

$p = array_unique(array_map('strtolower', $a));
Sign up to request clarification or add additional context in comments.

Comments

0

You can use array_flip to swap keys and values:

$a = array_flip(array_map('strtolower', $a));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.