0

Here is my output: im using more foreach loop with different condition and values put into same array name $returnVal[]=

EX:

foreach($val1 as $vals)
{
      $returnVal[]=$vals;
}




foreach($val2 as $vals)
  {
      $returnVal[]=$vals;
  }



 foreach($val3 as $vals)
  {
      $returnVal[]=$vals;
   }



 foreach($val4 as $vals)
   {
      $returnVal[]=$vals;
   } `

Im getting Output:

 Array
    (
        [0] => Array
            (
                [0] => 39705--COLUMBUS--LOWNDES--MS
                [1] =>  39702--COLUMBUS--LOWNDES--MS
                [2] =>  39710--COLUMBUS--LOWNDES--MS
                [3] =>  39701--COLUMBUS--LOWNDES--MS
            )

        [1] => Array
            (
                [0] => Array
                    (
                        [0] => 39705--COLUMBUS--LOWNDES--MS
                        [1] =>  39702--COLUMBUS--LOWNDES--MS
                        [2] =>  39710--COLUMBUS--LOWNDES--MS
                        [3] =>  39701--COLUMBUS--LOWNDES--MS
                    )

            )

        [2] => Array
            (
                [0] => Array
                    (
                        [0] => 39705--COLUMBUS--LOWNDES--MS
                        [1] =>  39702--COLUMBUS--LOWNDES--MS
                        [2] =>  39710--COLUMBUS--LOWNDES--MS
                        [3] =>  39701--COLUMBUS--LOWNDES--MS
                    )

                [1] => Array
                    (
                        [0] => Array
                            (
                                [0] => 39705--COLUMBUS--LOWNDES--MS
                                [1] =>  39702--COLUMBUS--LOWNDES--MS
                                [2] =>  39710--COLUMBUS--LOWNDES--MS
                                [3] =>  39701--COLUMBUS--LOWNDES--MS
                            )

                    )

                [2] => 57038--JEFFERSON--UNION--SD
            )

        [3] => 57049--NORTH SIOUX CITY--UNION--SD
    )

My Question: remove duplicate values and merge into one level

1 Answers1

1

Push element if it is not exists in the result array, this will avoid duplicate entries. Try the code below,

$returnVal = [];
foreach($val1 as $vals)
{
    if (!in_array($vals, $returnVal)) {
        $returnVal[]=$vals;
    }

} ..etc and so on 
Nithin John
  • 897
  • 3
  • 8
  • 21
  • @karthik : your required result is not mentioned here, and not a word about $val2,3.. arrays . If you clarify then I can help you better. – Nithin John May 19 '17 at 06:02
  • `foreach($stateSearch as $res4) { $where = ' state="'.$res4.'" '; $return =$this->cityCountyZip_Return($cleansedObName,$where); $ZipLists[]=$this->returnZipValues($return, $ZipLists); }` this is my code – Karthik Saravanan May 19 '17 at 06:08