skip to Main Content

How to get unique values from this array and save them in the table $tab = array('one','two','tree'); ?

    array(2) {
  [0]=>
    array(1) {
     ["tagi"]=>
        string(183) "photoshop, grafika, animacje,photoshop, grafika, animacje,photoshop, grafika, animacje,photoshop, grafika, animacje,photoshop, grafika, animacje,photoshop, grafika, animacje, tutorial"
  }
  [1]=>
    array(1) {
      ["tagi"]=>
        string(38) "photoshop, grafika, animacje, poradnik"
  }
}

3

Answers


  1. Chosen as BEST ANSWER

    How to remove empty lines ?

    array(6) {
          [0]=>
          string(9) "photoshop"
          [1]=>
          string(7) "grafika"
          [2]=>
          string(8) "animacje"
          [12]=>
          string(8) "tutorial"
          [16]=>
          string(8) "poradnik"
          [17]=>
          string(0) ""
        }
    

  2. if $mainArray = array(2)… , try this code:

    $mainString = "";
    foreach($mainArray as $array){
      foreach($array as $row){
        $mainString .= $row;
      } $mainString .= ", ";
    }
    
    $tempArray = explode(", ", $mainString);
    
    $finishArray = array_unique($tempArray);
    
    Login or Signup to reply.
  3. Try array_unique. This function takes one array as argument and generates a new array with distinct values of the argument array.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search