PHP have three style of Arrays
Syntax - array() ; Single Dimensional $arr = array("one" , 2) ; // Display array values using index. echo $arr[0] ; // Display one echo $arr[1] ; // Display 2 Destory the array - using unset() function and also use for unset the value of variable Example: unset($arr) ; // delete an array unset($arr[0]) ; // delete element in array Access using loops. for-loops count(array) - return the length of an array for($i = 0; $i < count($arr); $i++) { echo $arr[$i] ."<br>"; // echo the content with concat with HTML <br> tag that breaks the lines. } or foreach($arr as $val) { echo $val ; // here $arr iterate and store the value in $val } or test the content in array PHP Provide print_r(array) function - return the array in human readable form with all index and values. display like JSON format Example : use HTML pre tag that format text and, also work well without pre tag echo "<pre>" ; print_r($arr) ; echo "</pre>" ; Output: Array
Example : echo json_encode($arr) ; Output : ["one",2]and similar also provide json_decode($json) function that convert JSON format in PHP arrays. Key Value Pairs Multidimensional Array Complete array function in PHP |