Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Convert a multidimensional array to string?

Tags:

php

I'm working on a small ajax application and need to see if the values being generated in the background are what is expected. The value returned by the quest can be quite a complex multidimensional array, is there a way to convert this into a string so that it can be shown with alert?

Is there any other way of seeing these values?

Any advice appreciated.

Thanks.

like image 294
Dan Avatar asked Nov 19 '09 16:11

Dan


People also ask

How to convert an array into string PHP?

To convert an array to a string, one of the common ways to do that is to use the json_encode() function which is used to returns the JSON representation of a value. This function takes any value as input except resource.

How do I echo an array in PHP?

How do I echo an array in PHP? Use foreach Loop to Echo or Print an Array in PHP. Use print_r() Function to Echo or Print an Array in PHP. Use var_dump() Function to Echo or Print an Array in PHP.

How to convert input into string in PHP?

PHP | strval() Function The strval() function is an inbuilt function in PHP and is used to convert any scalar value (string, integer, or double) to a string.

What is a multidimensional array in PHP?

A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.


1 Answers

print_r, var_dump or var_export are good candidates. while coding an ajax application, you might also want to look at json_encode.

like image 128
knittl Avatar answered Oct 20 '22 23:10

knittl