Numeric array in php

In this tutorial learn how work array in php, In PHP, there are three types of arrays: Indexed/numberic arrays, Associative arrays and Multidimensional arrays in php.

Indexed arrays - In Arrays with a numeric index, value are stored and access in linearly. 
Associative arrays - In Arrays with named keys, value can stored associative with keys value also
Multidimensional arrays - In Arrays containing one or more arrays



The numeric index can be assigned automatically (index always starts at 0), like this:

$data = array("one","two","three","four","five"); 

Or can be Manually assign also
 $data[0] = "one";
 $data[1] = "two";
 $data[2] = "three";
 $data[3] = "four";
 $data[4] = "five";
To loop through and print all the values of an indexed array, you could use a foreach loop, like this:

<?php
         /* Method to create array with start from zero index. */  
         $data[0] = "one";
         $data[1] = "two";
         $data[2] = "three";
         $data[3] = "four";
         $data[4] = "five";
         
         foreach( $data as $value ) {
            echo "data value is ".$value."<br />";
         }
      

?>
Above Example Output:

data value is one
data value is two
data value is three
data value is four
data value is five

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...