Home  >  Article  >  Backend Development  >  How to use arrays in php

How to use arrays in php

墨辰丷
墨辰丷Original
2018-06-13 09:43:361925browse

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
   , ...
)

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);
?>

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!

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