"Five" PHP array operation function (not finished)

Source: Internet
Author: User

1. Structure of the output array: bool Print_r (array);

$arr=array(' Jack ', ' Mike ', ' Tom '); Print_r ($arr); //

2. How do I declare a two-bit array?

$arr=array(' name ' = =array(' Jack ', ' Mike '), ' sex ' = =array(' Man ', ' woman ') )); Print_r ($arr); // Array ([name] = = Array ([0] = + Jack [1] = Mike) [sex] = = Array ([0] = man [1] = = woman))

3. Traversal array The Foreach method is described in the third section of the 8th Stem of PHP: http://www.cnblogs.com/JhoneLee/p/3773616.html

4. String variable groups: Array explode (string boundary, string converted string, integer array max element Upper)

  $arr  =explode  (' A ',  $str  );  print_r  ( $arr ); //  Remove the array as a boundary of a group of//array ([0] = [1] = = BH [2] = = BS [3] = b [4] => ; FB [5] = db [6] = b [7] = CB [8] = =/-----------------------------------------------------  $arr  =explode  (' A ',  $str , 3); print_r  ( $arr ); //  Removes the array as a boundary, but because the upper limit is set, the last string is no longer split//array ([0] = [1] = BH [2] = BSABAFBADBA BACBA)  

5. Change the array to a string: string implode (string delimiter, array is transformed);

$arr 2=array(' Jack ', ' Mike ', ' Tom '); $arr=array(' name ' = = 'array(' Jack ', ' Mike ', ' Tom '), ' sex ' = =array(' Male ', ' female ') )); $str=implode(' ¥ ',$arr 2); // Jack¥mike¥tom $str=implode(' ¥ ',$arr); // Two-dimensional array error

6. Number of statistics arrays: count (array is counted, whether recursive (1: Yes, others: not));

$arr 2=Array(' Jack ', ' Mike ', ' Tom ');$arr=Array(' name ' = =Array(' Jack ', ' Mike ', ' Tom '), ' sex ' =Array(' Man ' =Array(' true ', ' false '), ' woman '));Echo Count($arr 2);//3Echo Count($arr);//2Echo Count($arr, 1);//9 Recursive statistics the number of multidimensional arrays here can only be 1, for other integers can only be recursive statistics

7. Retrieve the position of the value in the array: Array_search (check, array checked, check type);

$arr 2=Array(' Jack ', ' Mike ', ' Tom ', 1);$arr=Array(' name ' = ' Jack ', ' sex ' = ' male ');Echo Array_search(' 1 ',$arr 2);//3Echo Array_search(' 1 ',$arr 2,TRUE);//not displayed because the type is not correctEcho Array_search(' Jack ',$arr);//name//multidimensional array can only search arrays

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.