How to use array in PHP

In this article, I will explain how the array() function can be used in PHP.
  • 1986

array() function in PHP

  • array() creates an array, with keys and values.

  • In array(), If you want to skip the keys when you specify an array.

  • In array(), key is generated automatically in integer type, starting at 0 and increases by 1 for each value.

  • In array(), the parameters can be given an index with the => operator

Syntax

array(key=>value)

Parameter

Key key is the optional parameter. the key is determine in two type numeric or string. If not set, an integer key is generated, starting at 0.

value value is the Required parameter. Specifies the value.

Example

The following example show to how the array() function can be used in PHP.

<h3 style="color: tomato;">array example in PHP</h3>

<?php

$i=array("1"=>"Aman <br/>","2"=>"Ravi <br/>","3"=>"Manish <br/>","4"=>"Arvind <br/>");

print_r($i);

?>

 

Output

array.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.