Home > Backend Development > PHP Tutorial > PHP array operations subtotal

PHP array operations subtotal

WBOY
Release: 2016-07-29 09:02:51
Original
1097 people have browsed it

Manipulating arrays in PHP is the most basic and commonly used operation. PHP has many built-in convenient functions for us to use. However, the translation of official documents is sometimes not so easy to understand, and some functions usually require a lot of concepts to be understood every once in a while. mix. A good memory is not as good as a bad writing. I will slowly record some functions that I usually use here, and do demos just to understand how to use them.

1. Array merging

Array merging is originally a very simple thing, but the simpler something is, the easier it is to forget, especially when it is rarely used. . . .

<?php
echo "<PRE>";
$a=[1,2,3];
$b=[4,5,6];
//1.PHP数组合并函数
$c=array_merge($a,$b);
var_dump($c);
//2.直接数组相加 有顺序 按照键覆盖,后面键覆盖前面键的值
$c=$a+$b;
var_dump($c);
//3.
$c=$b+$a;
var_dump($c);

//4.这种给大家理解一下push,是不行的
array_push($a,$b);
var_dump($a);
Copy after login
results:
1.
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}
2.
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
3.
array(3) {
  [0]=>
  int(4)
  [1]=>
  int(5)
  [2]=>
  int(6)
}
4.
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  array(3) {
    [0]=>
    int(4)
    [1]=>
    int(5)
    [2]=>
    int(6)
  }
}
Copy after login

The above has introduced a subtotal of PHP array operations, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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