0

how can i convert this array to string?

public static function generos($string) {
   return preg_replace(array("/(natacao)/"),explode(" ","Natação"), $string);
}

public function categoria($string) {
    $this->exp = explode(",", $string);
    foreach ($this->exp as $this->list) :
        return $this->generos(implode(",", $this->list));
    endforeach;
}

echo '<li>'.$this->categoria($rows[] = $this->row['categoria']).'</li>';

table

id  |  categoria  
 1  |  futebol, voleiball

Current results

<li>futebol, voleiball</li>

expected result

<li>futebol</li>
<li>voleiball</li>
mehid
  • 47
  • 6
  • Where is `
  • ` and `
  • ` coming from? I don't see it anywhere in the code. – Barmar Aug 12 '19 at 18:11
  • Possible duplicate of [Array to String PHP?](https://stackoverflow.com/questions/7490488/array-to-string-php) – spicy.dll Aug 12 '19 at 18:11
  • The `return` statement is ending the `foreach` loop during the first iteration. I don't see how you're getting both `futebol` and `voleiball` in the output. – Barmar Aug 12 '19 at 18:12
  • It's generally not a good idea to store comma-separated lists in a database column. You should normalize your data. But that's a separate issue from this problem. – Barmar Aug 12 '19 at 18:13
  • `implode(",", $this->list)` makes no sense. `$this->list` is a string, but the second argument to `implode()` should be an array. – Barmar Aug 12 '19 at 18:14
  • @Barmar `string(19) "futebol, voleiball" return var_dump($this->generos(implode(",", $this->exp)));` – mehid Aug 12 '19 at 20:19
  • @AbraCadaver exactly what I need – mehid Aug 12 '19 at 20:22
  • `$this->exp` is a list, but `$this->list` is one of the elements of that list, which is just a string. – Barmar Aug 12 '19 at 20:22