Convert array to string in PHP 7 — Phpflow.com

in this post, We’ll convert the array elements into string. We are going to convert the array to string using three methods.

Array to String in PHP

Let’s convert array elements to string using PHP 7. We’ll discuss implode(), json_encode() and join() method and create sample example to convert array to string.

Convert Array to String Using implode()

The implode() method is a PHP built-in function for joining the items of an array. We just need to pass two parameters, One is an array of strings and the second is a delimiter (string to be used between the pieces) of your response string.

The delimiter is used to join them together into one string.

Syntax: implode (separator, array) Let's take a simple example -

PHP Array to String Using json_encode()

The json_encode() function is a PHP inbuilt function that converts a PHP array or object to a JSON representation.

Syntax: string json_encode( $value, $option, $depth ) The sample example:

Array to String Using join()

The join() method is a PHP built-in function that connects an array of elements separated by a string.

Syntax: string join( $separator, $array) The sample example:

Originally published at https://www.phpflow.com on November 20, 2021.

--

--

--

Hey, I am Parvez Alam. A software developer since 2009. I am a programming addict. I love learning and sharing knowledge. https://www.phpflow.com/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parvez Alam

Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I am a programming addict. I love learning and sharing knowledge. https://www.phpflow.com/

More from Medium

PHP for Beginners: Loops

Front End application for CRUD APIs with PHP ,Laravel & Blade

10 Resources to Learn Web Development with PHP

Could Not Open Input File: Artisan In Laravel