- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Stripping last comma from a foreach loop in PHP?
Below is the code that can be used to strip the last comma from the foreach loop −
Example
$result_str = array("Hi", "Hello", "have a", "good day"); foreach ($results as $result) { $result_str[] = $result->name; } echo implode(",",$result_str);
Output
This will produce the following output −
Hi,Hello,have a,good day
Advertisements