Home > Backend Development > PHP Tutorial > How to use arrays in php

How to use arrays in php

墨辰丷
Release: 2023-03-31 20:58:02
Original
2007 people have browsed it

This article mainly introduces the rules for using arrays in PHP. It analyzes the usage of arrays in PHP with examples. It has certain reference value. Friends in need can refer to it.

This article analyzes the usage of arrays in PHP with examples. rule.

The specific analysis is as follows:

Arrays occupy a very important position in PHP. Values ​​such as strings, pictures, numbers, and videos all exist in the form of arrays, so it is necessary to understand the various rules of arrays.

1, key, value.

The basic form of an array:

array( [key =>]
value
   , ...
)
Copy after login

key=>value, where the key can only be two types, integer and string. The value can be in various forms. Except for numbers, other values ​​must be enclosed in strings with '' or "". The following example illustrates the rules:

<?php  
$a = array(-1=>2,
         -2=>3,
   &#39;01&#39;=>&#39;99.jpg&#39;,
            8,
           &#39;a&#39;,
     &#39;b&#39;=>TRUE,
         NULL,
            "",
      1.2=>0.5,
        );
  
     print_r($a);
?>
Copy after login

Output result: Array ( [-1] => 2 [-2] => 3 [01] => 99.jpg [0] => 8 [1] => 0.5 => 1 [2] => [3] => )

Summary: The above is the entire content of this article, I hope it can help Everyone’s learning helps.

Related recommendations:

PHP’s practical functions for implementing black and white lists

How does PHP list all databases in MySQL

How to add subtitles to video using php using ffmpeg

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

Related labels:
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