Jump to content

Help with Combining Array Values


perezf

Recommended Posts

if you mean remove duplicate values use array_unique

 

<?php
$old_array = array(10, 16, 17, 10, 11, 12);
print_r($old_array);

$new_array = array_unique($old_array);
print_r($new_array);
?>

 

returns

 

Array
(
 [0] => 10
 [1] => 16
 [2] => 17
 [3] => 10
 [4] => 11
 [5] => 12
)

Array
(
 [0] => 10
 [1] => 16
 [2] => 17
 [3] => 11
 [4] => 12
)

 

One thing to note is that this will only work of duplicate value === duplicate value e.g. an array containing 10 and '10' will see these as different values as one is an integer and the other is a string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.