How To Convert 2 Dimensional Array Into A String Using PHP

Hello developers, as being a developer everyday we explore our skills with some new tasks,sometimes it becomes hectic to solve a particular problem or sometimes hard tasks get eliminated with minimal effort,but all in all we face various problems and give our best to conquer those problems.

So today in our tutorial we are here with a short and interesting topic or task which anyone of us can face while development of a project, that is Converting a 2 dimensional Array Into a String Using PHP.

Let say we have a array of resultant rows which we have fetched from database according to a particular condition and the resultant array is two dimensional,now the problem is that we have to check that the results of a particular column are existing or not in some other table.For solving this problem we have to convert the resultant array into a single string and then we can check each result in the database table whether it exists or not simply.

The problem seems to be a complex one but solution is easy and simple.

We are assuming that we have this array:
$array = array (
array (’01’,’03’,’02’,’15’),
array (’05’,’04’,’06’,’10’),
array (’07’,’09’,’08’,’11’),
array (’12’,’14’,’13’,’16’)

In which case, we can do this:
$tmpArr = array();
foreach ($array as $sub) {
$tmpArr[] = implode(‘,’, $sub);
$result = implode(‘,’, $tmpArr);
echo $result;

This will simply convert our two dimensional array into string and the output will be

So, thats how we can convert the 2 Dimensional array into a string using PHP.
Hope the tutorial will be useful for our developers.Our team is working hard to help you guys please
comment and contact us with your query and challenges.We feel happy to help you guys.
Work more learn more
Because Hurdles aren’t really hurdles

Be First to Comment

Leave a Reply

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