Exploding a list into a nested list array, and then into a multidimensional array in PHP

Hits: 32

Today, I show you how to convert (explode) a list, in this case a list of authors, first and last names separated by a comma, into a nested list array, and then iterate through the nested list array and convert (explode) into a multidimensional array:

 

 

OUTPUT OF THE CODE:

List of authors (string):

Carlo Carandang,Mimi Carandang

Explode into a nested list array:

Array
(
[0] => Carlo Carandang
[1] => Mimi Carandang
)

Space replaced by a comma:

Array
(
[0] => Carlo,Carandang
[1] => Mimi,Carandang
)

Iterate through the array, and explode into a multidimensional array:

Array
(
[0] => Carlo
[1] => Carandang
)
Array
(
[0] => Mimi
[1] => Carandang
)

Now you are ready to parse and analyze the data in the array!

 

photo credit: Christiaan Colen Locky ransomware: source code via photopin (license)