How to get value in php array

(*-*)浩
Release: 2023-02-24 09:56:01
Original
5345 people have browsed it

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);
Copy after login

Define the first of the array Two ways:

Assignment definition

$a[] =1;
$a[] =2;
$a[] =3;
Copy after login

The third way to define an array:

Define an associative array

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

Array value

Get the value based on the index array:

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

Get the value based on the key Value:

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

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template