Table of Contents

    Arrays in PHP: Storing and Manipulating Data

    Arrays in PHP: Storing and Manipulating Data

    An array stores multiple values in one single variable.

    In the following example $cars is an array. The PHP var_dump() function returns the data type and value:

    Example Code:

    
    
    <?php
    
    $name = array("Ram","Shyam","Zodu");
    var_dump($name);
    
    ?>
    
    

    Output:

    The above code will produce the following result-

    
    array(3) { [0]=> string(3) "Ram" [1]=> string(5) "Shyam" [2]=> string(4) "Zodu" }
    

    Code: Array Traversing

    
    <?php
    	$num = array(12, 24, 3, 64, 5);
    
    	foreach($num as $val) {
    		echo $val. "</br>";
    	}
    
    ?>
    
    

    Output:

    The above code will produce the following result-

    
    12
    24
    3
    64
    5