Home > Article > Backend Development > How to use php's index array and associative array
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!