Home  >  Article  >  Backend Development  >  How to get value in php array

How to get value in php array

(*-*)浩
(*-*)浩Original
2019-09-17 14:53:105281browse

PHP array

Features: It can store any type of data, it can be discontinuous, it can be indexed or associated

How to get value in php array

What is an index?

is the common array style. The index starts from 0, 1, 2, 3. To define an array, you put values ​​directly into it, and only the index is automatically generated, so it usually starts from 0, like this The array is an indexed array, and the indexes are consecutive. (Recommended learning: PHP programming from entry to proficiency)

What is association?

is our hash table set. When defining it, it must be given a key and a value. The two are related, and the values ​​corresponding to the key are related.

Define an array

The first way to define an array:

Define simply index the array

$a = array(1,2,3);

Define the first of the array Two ways:

Assignment definition

$a[] =1;
$a[] =2;
$a[] =3;

The third way to define an array:

Define an associative array

$a = array(
"one"=>"hello",
"two"=>100,
"three"=>9.9
);

Array value

Get the value based on the index array:

$a = array(1,2,3);
echo $a[0];

Get the value based on the key Value:

$a = array(
"one"=>"hello",
"two"=>100,
"three"=>9.9
);
echo $a["three"];

The above is the detailed content of How to get value in php array. For more information, please follow other related articles on the PHP Chinese website!

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