Home  >  Article  >  Backend Development  >  Array Operation_PHP Tutorial

Array Operation_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:26:31741browse

PHP supports both scalar arrays and associative arrays. In fact, there is no difference between the two. You can create an array using the list() or array() functions, or you can explicitly set the value of each array element.
$a[0] = "abc";
$a[1] = "def";
$b["foo"] = 13;
You can also add to the array Numeric values ​​to create an array.
$a[] = "hello"; // $a[2] == "hello"
$a[] = "world"; // $a[3] == "world"
Arrays can be sorted through the functions asort(), arsort(), ksort(), rsort(), sort(), uasort(), usort(), and ksort(). Which function to use depends on your needs. It depends on the type of sorting you want.
You can use the cunt() function to count the number of elements in an array.
You can use the next() and prev() functions to traverse the array. Another common way to iterate over an array is to use the function each().

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531953.htmlTechArticlePHP supports both scalar arrays and associative arrays. In fact, there is no difference between the two. You can use the function list() or array() to create an array,...
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