How to Convert String to Array Conversion in Laravel?

In this tutorial we’re going to learn how to convert string to Array Conversion in laravel. This tutorial will give you a simple example of string to array conversion in laravel.

I will give you the following two examples of laravel string to array conversion in controller file and blade file.

  • 1. How to Convert String to Array in Laravel Controller
  • 2. How to Convert String to Array in Laravel Blade

we will use explode() to convert string into array in laravel.

1st example go to your controller and use below function

public function index()
        $string = "Amit, Sumit, Monu, Rahul, Raju";

        $stringArray = explode(",", $string);


2nd example go to your blade page and put below code

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    $string = "Amit, Sumit, Monu, Rahul, Raju";
    $stringArray = explode(",", $string);

@foreach ($stringArray as $value)
    <li>Value: {{ $value }}</li>



Now all data is coming successfully. 👍👍

Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.

Related Posts

Laravel 9 Import Export Excel & CSV File Example

In this tutorial will learn how to easily import and export Excel and CSV files in the Laravel 8 application while communicating with the PHP MySQL database…

Laravel 9 CRUD Example Tutorial for Beginners

In this tutorial i’m going to learn how to do crud operation in laravel for beginners so follow this tutorial i have descibed in very easy way….

composer unable to install laravel/passport

I have created a new project with using “composer i installed” When i trying to install passport using following errors are their Solution:-

How to upload Multi Image in Laravel 9 ?

In this tutorial im going to learn how to upload multi image in laravel in easy steps so follow these tutorials. 1st step create model and migration…

What are the difference between SQL and MySQL ?

SQL (Structured Query Language): SQL is a domain-specific language used for managing and manipulating relational databases. It is a standardized language for relational database management systems (RDBMS)…

What is traits and using of laravel ?

Traits are a way to group and reuse code in a fine-grained and consistent manner. They are similar to classes, but are intended to group functionality in…

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x