Home > Backend Development > PHP Tutorial > PHP study notes - PHP array summary

PHP study notes - PHP array summary

WBOY
Release: 2016-07-25 08:58:22
Original
855 people have browsed it
  1. foreach($arr as $key=>$value)
  2. {
  3. echo $value."
    ";
  4. }
Copy code

2), when $arr[ ] When assigning, the array subscript will be the current maximum subscript + 1 ($arr [max + 1]) as the subscript. Example:

 <?php
 $arr= array(1,'str',false);
 $arr[4]='4';
 $arr[]='x';
 $arr['int2']='7';
 $arr[]='xx';
 
 foreach($arr as $key=>$value)
 {
 echo $key.' ='.$value."<br>";
 }
 //output:
/*
0 =1
1 =str
2 =
4 =4
5 =x
int2 =7
6 =xx
*/
?>
Copy after login

4. Arrays in php will dynamically increase by themselves, which is different from c++. 5. Functions about arrays 1), count counts the number of arrays. 2), isarray determines whether a variable is an array 3), explode text segmentation. 4), unset destroys an element of a variable or array. The sequence of the array will not be changed after unset is destroyed. 6. Array operators $a+$b adds array b to array a, removing identical keys. Identical keys are not overwritten. The same goes for numerical subscripts

<?php
$a=array('a'=>'fsf','b'=>'fsdfss');
$b=array('a'=>'china','b'=>'huc','c'=>'lengai');
$c=$a+$b;
print_r($c);//Array ( [a] => fsf <strong> => fsdfss [c] => lengai )
?>
Copy after login

Code description: $a==$b The key values ​​of array a and array b are the same $a===$b Arrays a and b not only have the same key values, but the order must also be the same. $a$b array a and array b are different. $a!==$bArray a and array b are not congruent. Let’s summarize these, I hope it will be helpful to everyone. To learn PHP programming, come to Programmer’s Home.



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