Php array, correction, traversal, function, etc.

Source: Internet
Author: User
Php array, modification, traversal, functions, and other php & nbsp; W3c & nbsp; php array, modification, traversal, function, etc.

Php W3c http://www.w3school.com.cn/php/func_array_search.asp


Php array format:

①, Numerical array

Format: array (v1, v2, v3, v4 ,.....)

Array (value 1, value 2, value 3 ,......)

② Join an array

Format: array (k1 => v1, k2 => v2, k3 => v3 ,.......)

Array (key 1 => value 1, key 2 => value 2, key 3 => value 3 ,......)

③ Multi-dimensional data

$ Arr_arr = array (4567, 77.7, 99,100), "aa", "bb", cc );


Data Display:

Print_r ()

Var_dump () (contains the type, length, and other information)

$ Arr = array (1, 2, 3, 4, 5 );
Print_r ($ arr );
Echo"
";
Var_dump ($ arr );

The result is:

Array ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5)
Array (5) {[0] => int (1) [1] => int (2) [2] => int (3) [3] => int (4) [4] => int (5 )}

Array traversal foreach ():

$ Arr = array (1, 2, 3, 4, 5 );

Foreach ($ arr as $ k =>$ v ){
Echo "key => value is". $ k. "=>". $ v ."
";
}

Multi-dimensional array output:

$ Arr_arr = array (4567, 77.7, 99,100), "aa", "bb", cc );
Echo "var_dump multi-dimensional array
";
Var_dump ($ arr_arr );
Echo "print_r () multi-dimensional array
";
Print_r ($ arr_arr );

Display:

Var_dump multi-dimensional array
Array (4) {[0] => array (4) {[0] => int (4567) [1] => float (77.7) [2] => int (99) [3] => int (100)} [1] => string (2) "aa" [2] => string (2) "bb" [3] => string (2) "cc"} print_r () multi-dimensional array
Array ([0] => Array ([0] => 4567 [1] => 77.7 [2] => 99 [3] => 100) [1] => aa [2] => bb [3] => cc)

Array functions:

Delete function: unset ($ arr ['K']);

Value sorting: sort (), rsort () (reverse)

Key sorting: ksort (), krsort ()

Sum: array_sum ($ array)

Number: count () <----> sizeof ()

Search: in_array (value, $ array)

Array_search (value, $ array)

Look at the W3Cschool, paste a directory, and get familiar with the learning plan:

I. php Basics

PHP Basics
  • PHP Tutorial
  • PHP introduction
  • PHP installation
  • PHP syntax
  • PHP variables
  • PHP string
  • PHP operators
  • PHP If... Else
  • PHP Switch
  • PHP array
  • PHP loop
  • PHP functions
  • PHP form
  • PHP $ _ GET
  • PHP $ _ POST
2. php advanced

PHP advanced
  • PHP date
  • PHP Include
  • PHP files
  • PHP file Upload
  • PHP Cookies
  • PHP Sessions
  • Php e-mail
  • PHP secure E-mail
  • PHP Error
  • PHP Exception
  • PHP Filter
III. php database

PHP database
  • MySQL introduction
  • MySQL Connect
  • MySQL Create
  • MySQL Insert
  • MySQL Selecth
  • MySQL Where
  • MySQL Order
  • MySQL Update
  • MySQL Delete
  • PHP ODBC
4. php and xml

PHP XML
  • XML Expat Parser
  • XML DOM
  • XML SimpleXML

V. php and ajax

PHP and AJAX
  • AJAX introduction
  • XMLHttpRequest
  • AJAX Suggest
  • AJAX XML
  • AJAX Database
  • AJAX responseXML
  • AJAX Live Search
  • Ajax rss Reader
  • AJAX Poll

VI. php Reference Manual

PHP Reference Manual
  • PHP Array
  • PHP Calendar
  • PHP Date
  • PHP Directory
  • PHP Error
  • PHP Filesystem
  • PHP Filter
  • PHP FTP
  • PHP HTTP
  • PHP LibXML
  • PHP Mail
  • PHP Math
  • PHP MySQL
  • PHP SimpleXML
  • PHP String
  • PHP XML
  • PHP Zip
  • PHP Miscellaneous


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.