How to display array structure and values in PHP ? Last Updated : 07 Oct, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to display the array structure and values in PHP. To display the array structure and its values, we can use var_dump() and print_r() functions. It includes Array sizeArray valuesArray value with IndexEach value data type We will display the array structure using var_dump() function. This function is used to dump information about a variable. This function displays structured information such as the type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure. This function is also effective with expressions. Syntax: var_dump( $array_name ) Parameters: The function takes a single argument $array_name that may be one single variable or an expression containing several space-separated variables of any type. Return Type: Array Structure Example: PHP Program to create an array and display its structure. PHP <?php // Array with subjects $array1 = array( '0' => "Python", '1' => "java", '2' => "c/cpp" ); // Display array structure var_dump($array1); ?> Outputarray(3) { [0]=> string(6) "Python" [1]=> string(4) "java" [2]=> string(5) "c/cpp" } Here, array(3) is the size of the array ( 3 elements)string(6) is the data type of element 1 with its sizestring(4) is the data type of element 2 with its sizestring(5) is the data type of element 3 with its size Array Values: We will display the array values by using the print_r() function. This function is used to print or display information stored in a variable. Syntax: print_r( $variable, $isStore ) Parameters: $variable: This parameter specifies the variable to be printed and is a mandatory parameter.$isStore: This is an optional parameter. This parameter is of boolean type whose default value is FALSE and is used to store the output of the print_r() function in a variable rather than printing it. If this parameter is set to TRUE then the print_r() function will return the output which it is supposed to print. Return Value: Array with values. Example: PHP program to display an array of values. PHP <?php // Array with subjects $array1 = array( '0' => "Python", '1' => "java", '2' => "c/cpp" ); // Display array values print_r($array1); ?> OutputArray ( [0] => Python [1] => java [2] => c/cpp ) Comment More infoAdvertise with us Next Article How to display array structure and values in PHP ? M manojkumarreddymallidi Follow Improve Article Tags : Web Technologies PHP PHP-array PHP-function PHP-Questions +1 More Similar Reads How to Slice an Array in PHP? In PHP, slicing an array means taking a subset of the array and extracting it according to designated indices. When you need to extract a subset of elements from an array without changing the original array, this operation comes in handy. PHP comes with a built-in function called array_slice() to he 2 min read How to display string values within a table using PHP ? A table is an arrangement of data in rows and columns, or possibly in a more complex structure. Tables are widely used in communication, research, and data analysis. Tables are useful for various tasks such as presenting text information and numerical data.Tables can be used to compare two or more i 1 min read How to Populate Dropdown List with Array Values in PHP? We will create an array, and then populate the array elements to the dropdown list in PHP. It is a common task when you want to provide users with a selection of options. There are three approaches to achieve this, including using a foreach loop, array_map() function, and implode() function. Here, w 2 min read How to use array_merge() and array_combine() in PHP ? In this article, we will discuss about how to use array_merge() and array_combine() functions in PHP. Both functions are array based functions used to combine two or more arrays using PHP. We will see each function with syntax and implementation array_merge() FunctionThis function merges the two or 3 min read How to create an array with key value pairs in PHP? In PHP, an array with key-value pairs is called an associative array. It maps specific keys to values, allowing you to access elements using custom keys rather than numerical indices. Keys are strings or integers, while values can be of any data type.Here we have some common approaches to create an 2 min read How to Loop Through an Array using a foreach Loop in PHP? Given an array (indexed or associative), the task is to loop through the array using foreach loop. The foreach loop iterates through each array element and performs the operations. PHP foreach LoopThe foreach loop iterates over each key/value pair in an array. This loop is mainly useful for iteratin 2 min read How to convert an array to CSV file in PHP ? To convert an array into a CSV file we can use fputcsv() function. The fputcsv() function is used to format a line as CSV (comma separated values) file and writes it to an open file. The file which has to be read and the fields are sent as parameters to the fputcsv() function and it returns the leng 2 min read How to take user input for two dimensional (2D) array in PHP ? There are two methods to take user input in PHP in two dimensional (2D) array. Approach 1:Â Use HTML forms through PHP GET & POST method to take user input in two dimensional (2D) array.First, input data into HTML forms.Then use the GET or POST method of PHP to get or post those input data into 3 min read How to find the index of an element in an array using PHP ? In this article, we will discuss how to find the index of an element in an array in PHP. Array indexing starts from 0 to n-1. Here we have some common approachesTable of ContentUsing array_search() FunctionUsing array_flip()Using a custom functionUsing a foreach LoopUsing array_keys FunctionUsing ar 6 min read How to get the POST values from serializeArray in PHP ? When working with forms in web development, it's common to use JavaScript to serialize form data into a format that can be easily sent to the server. One popular method for serializing form data is using jQuery's serializeArray() function. However, once the data is serialized and sent to the server 2 min read Like