Home >Backend Development >PHP Tutorial >How to use php's index array and associative array

How to use php's index array and associative array

php中世界最好的语言
php中世界最好的语言Original
2018-03-24 17:02:142200browse

This time I will show you how to use PHP's index array and associative array. What are the precautions for using PHP index array and associative array? The following is a practical case, let's take a look.

The index array in php refers to an array with numbers as keys. And this key value is self-increasing

Associative array means that one key value corresponds to one value, and this key value is irregular and is usually specified by ourselves.

There is another difference between them. After the index array is converted into json, it becomes an array. The associative array is converted into json and becomes an object. Usually when we write interfaces for the app, we use index arrays to convert them into json and pass them there. The client side is more friendly to arrays.

Points to note:

$arr = [0=>1,2=>3a];

The above array $arr converted to json will be in object form.

$arr = ['a','b'];

The $arr here is converted into json and is in the form of an array

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to generate random numbers in PHP

##Forced downloading of QR code images

The above is the detailed content of How to use php's index array and associative 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