Home  >  Article  >  Backend Development  >  PHP array definition and usage examples (php array definition method)_PHP tutorial

PHP array definition and usage examples (php array definition method)_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:07759browse

This is a PHP example about arrays. It briefly explains the basic use of arrays. Comments are added to the example

Copy code The code is as follows:

//Define a string array
$fruit = array("apple", "orange");
//Reference array The value
$fruit[0];//The value represented is apple
$fruit[1];//The value represented is orange
//It is worth noting that the index of the array is from 0 At the beginning, everyone who has studied C and Java knows it.

//Define a numerical array
$number = array(1,2,3,4,5);//The value of the reference array is the same as above

//Define a Conforming array
$mix = array(1,"example","hello",2.5);//The value of the reference array is the same as above

//You can also define the array in key-value mode
$ex = array("a"=>"Fruit","b"=>"Car");
//You can reference it like this
$ex["a"];//Corresponding The value is fruit
$ex["b"];//The corresponding value is car
//You can also create such a key-value matching array
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/746864.htmlTechArticleThis is a PHP example about arrays. It briefly explains the basic use of arrays. Comments are added to the example. Copy the code as follows: ?php //Define a string array $fruit =...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn