How to Generate Array from a Comma Separated list Using PHP?

Keywords : – How do I create a comma-separated list from an array in PHP, Generate Array from a comma-separated list Using PHP, Split a comma delimited string into an array in PHP, How to Convert comma separated values to array with PHP

Solution:-

Hello Friends Today, Through this Tutorial, I will tell you how you can convert any comma value into an array by separating it. I will tell you the solution through php language by example today.

Your Question :- I have a variable defined like so: $var = “1, 2, 3, 4, 5”;

You Want solution as a like it :- $thePostIdArray = array(1, 2, 3, 4, 5);

<?php
$var = "1, 2, 3, 4, 5";
$arrayval = explode(', ', $var);
print_r($arrayval);
output :- Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
?>

explode () – It works by converting String to Array. It has two parameters. The first parameter is a Separator that tells where the string is to be broken, and the second parameter is given a string to convert to Array.