![]() Here, the foreach loop is used for iterating over the array of elements in $myarray. run foreach loop to every element of array. ![]() Solution 4: Using Foreach Loop to Print Element of an Array // Declare a PHP array ![]() So, the method takes the array and converts its elements into a string and joins them using a ‘,’ separator. Here, the method is passed ‘,’ as the separator and $myarray as the array argument. This method returns a string after accepting an array of elements as input. In this code, the implode() method is used. Convert array to string by using implode function. Solution 3: Using PHP Inbuilt Function implode() to Convert Array to String // Declare a PHP array Then it prints the elements in the form of key and value pairs as shown below. It first displays the type of the variable, which is an array in this case. Here, the var_dump method takes the parameter $myarray and prints out the type and the structured information about that variable. Solution 2: Using Built-in PHP Function var_dump // Declare a PHP array The keys here are the indexes and the values are the elements in those index positions. Here, the print_r method takes the parameter $myarray and prints its values in the form of keys and values. Output Array ( => 1 => 2 => 3 => 4 => 5 => 6 => 7 => 7 ) Associative Arrays in PHP Read Discuss Associative arrays are used to store key value pairs. Print PHP array using print_r() functions. Solution 1: Using Builtin PHP Function print_r // Declare a PHP array
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |