Menu
CodingPanel.com
  • Home
  • Technologies
    • Angular
    • C++
    • Java
    • JSON
    • JavaScript
    • Kotlin
    • PHP
    • React
  • Topics
    • Algorithms
    • Computer Science
    • Design Patterns
    • Software Design
    • Software Engineering
    • Web Development
  • Interview Questions
    • C# Interview Questions
  • Learn
    • My Learning
    • Data Structure
    • Programming
  • Jobs
    • Find a Job
    • Post a Job
    • Job Dashboard
CodingPanel.com

How to convert an Array to String in PHP?

Posted on August 1, 2020August 1, 2020 by CodingPanel Editor

In this article, you will learn how to convert an array into the string using PHP’s built-in function implode().
Syntax.

Convert an Array to String using PHP

The implode function takes two values as parameters.

implode ( string $glue , array $pieces ) : string

glue – It’s a value that is concatenated to each element of the array when output as a string. This can be skipped. But if there is nothing to “glue” the elements won’t have anything in between and appear adjacent.

array – It’s an array that you need to convert

<?php

$arr = ["pizza", "cake", "fruit salad"];
echo "Menu:" . implode($arr);

?>

Output:

As you see the elements are glued together without any space between these.

<?php
$arr = ["pizza", "cake", "fruit salad"];
$glue = " , ";
echo "Menu: " . implode($glue, $arr);

?>

Output:

Related posts:

  1. How to sort an array in JavaScript using Quick Sort Algorithm?
  2. Convert hexadecimal string to decimal integer in Java
  3. How to perform DNS lookup on a domain name in PHP?
  4. Remove vowels from a string using Java

1 thought on “How to convert an Array to String in PHP?”

  1. developer says:
    November 9, 2020 at 8:16 am

    I’ll likely to end up once again to see considerably more, many thanks for that information.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Blog Authors

avatar for Asha S.Asha S. (1)

IT specialist Veteran

avatar for CodingPanel EditorCodingPanel Editor (34)

Blog Hero

avatar for Feras SFeras S (4)

Software Engineer

Programming Courses

  • Learn C Programming
    by CodingPanel Editor
    32 Lessons
  • Learn C++ Programming
    by CodingPanel Editor
    12 Lessons
  • React Tutorial
    by CodingPanel Editor
    21 Lessons
©2021 CodingPanel.com | Powered by WordPress & Superb Themes