-4

I want to group this array. please help me..

Array
(
    [0] => dghfdih@hjuh.cvh
    [1] => dghfdih@hjuh.cvh
    [2] => dghfdih@hjuh.cvh
)

And my expected output is

 Array
    (
        [0] => dghfdih@hjuh.cvh

    )
  • _I want to group this array_ What does that mean? Group on what criteria? all elements are the same... what have you tried? – B001ᛦ Nov 14 '17 at 13:20
  • what is your expected output ? – shubham715 Nov 14 '17 at 13:20
  • Array ( [0] => dghfdih@hjuh.cvh ) – Subhankar Dutta Nov 14 '17 at 13:21
  • 1
    Do you mean [`array_unique`](http://php.net/manual/en/function.array-unique.php)? – iainn Nov 14 '17 at 13:22
  • You want to remove duplicate items..? – Param Kumar Nov 14 '17 at 13:22
  • We are always glad to help and support new coders but ***you need to help yourself first. :-)*** After [**doing more research**](https://meta.stackoverflow.com/q/261592/1011527) if you have a problem **post what you've tried** with a **clear explanation of what isn't working** and provide [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). – Jay Blanchard Nov 14 '17 at 13:23

2 Answers2

0

Look at array_unique which will remove duplicates from the array.

<?php
// Assuming your array is stored as $arr
$arr = array(
    'dghfdih@hjuh.cvh',
    'dghfdih@hjuh.cvh',
    'dghfdih@hjuh.cvh'
);
// Remove the duplicates
$arr = array_unique($arr);
// Print to test
echo '<pre>'.var_export($arr, TRUE).'</pre>';
kchason
  • 2,836
  • 19
  • 25
0

I assume you wish to remove duplicates, luckily PHP has a function called array_unique

Use it like so:

$array = array( "dghfdih@hjuh.cvh", "dghfdih@hjuh.cvh", "dghfdih@hjuh.cvh" );

$array = array_unique( $array );
Jesse Schokker
  • 896
  • 7
  • 19