Menu
  • HOME
  • TAGS

array_unique() not functioning as it should?

php,arrays,array-unique

You have to assign the output of array_unique to the array again like this: $votes = array_unique($votes); As a reference you can look at the manual: http://php.net/manual/en/function.array-unique.php And a quote from there: Takes an input array and returns a new array without duplicate values. ...

Get unique array for $key

php,arrays,array-unique

Use array_unique via array_map $result = array_map('array_unique', $result); ...

PHP, Remove duplicate and blank line

php,duplicates,array-unique

Check this, this is new code:- <?php $string_old = "2342 de20343 _ _ 23094 zz900 234432 zz900 2342"; $array_by_exploding_through_next_line = explode ("\n",$string_old); $new_array = array(); foreach($array_by_exploding_through_next_line as $key => $value){ if(strpos($array_by_exploding_through_next_line[$key], '_') !== FALSE || strpos($array_by_exploding_through_next_line[$key], ' ') !== FALSE){ }else{ $new_array[] = $value; } } $string_new = implode('',array_unique($array_by_exploding_through_next_line));...

Remove duplicate using array_unique

php,foreach,array-unique

You need to cache the values of $entity->galdesc you already used. An approach with in_array could look like this: <?php $tagnamesUsed = array(); ?> <?php foreach($entities as $entity): ?> <?php $str = str_replace(' ', '-', esc_attr($entity->galdesc)) ?> <?php if (!in_array($entity->galdesc, $tagnamesUsed)): ?> <li><a href="#" id="<?php echo $str ?>"><?php echo_safe_html(nl2br($entity->galdesc)); ?></a></li>...

Remove duplicates from multidimensional associative array in php if two values match

php,arrays,array-unique,array-map,array-intersect

<?php $data = array( array( 'time' => '17:16', 'city' => 'Bristol', 'amount' => 373, ), array( 'time' => '18:16', 'city' => 'Bristol', 'amount' => 373, ), array( 'time' => '18:16', 'city' => 'Wednesbury', 'amount' => 699, ), array( 'time' => '19:16', 'city' => 'Wednesbury', 'amount' => 699, ), ); $tmp...