Search code examples
phpstringimplode

PHP string implode: Invalid arguments passed in


$allProfiles = '';
foreach( array_merge( $profile, $otherProfiles )  as $all ):
    $allProfiles .= $all;
endforeach;

echo "Player all profiles: $allProfiles";

This prints for me Player all profiles: NameNameNameNameName, how can I implode by comma? When I make $allProfiles .= implode(",", $all); Then I got Invalid arguments passed in Thanks in advance

EDIT

Just changed $allProfiles .= $all; to $allProfiles[] = $all;

Then in echo used implode ..


Solution

  • Make array like this

     $allProfiles = array();
     foreach( array_merge( $profile, $otherProfiles )  as $all ):
           $allProfiles[]= $all;
     endforeach;
    
    echo "Player all profiles: ".implode(",",$allProfiles);