PHP array functions play a role in our encoding

Source: Internet
Author: User
PHP array functions are a very powerful set of functions. We can use these functions to sort, delete, and merge arrays. Today, we will introduce to you what role PHP array functions will play in our practical application. Hope to help beginners. If there is a... "> <LINKhref =" http://www.php100.com//statics/style/head

 

PHP array functions are a very powerful set of functions. We can use these functions to sort, delete, and merge arrays. Today, we will introduce to you what role PHP array functions will play in our practical application. Hope to help beginners.

If there is a large array and you need to find out whether it contains a specific element, you can use the PHP array function in_array (). The following example shows "Not found in this array", because Albert is searched in an array named $ namesArray, and such an element does Not exist in the $ namesArray array.

If there is a large array and you need to find out whether it contains a specific element, you can use the PHP array function in_array (). The following example shows "Not found in this array", because Albert is searched in an array named $ namesArray, and such an element does Not exist in the $ namesArray array.


  1.  
  2. $ LookingFor = "Albert ";
  3.  
  4. If (in_array ($ lookingFor, $ namesArray )){
  5.  
  6. Echo "You 've got it! ";
  7.  
  8. } Else {
  9.  
  10. Echo "Not found in this array! ";
  11.  
  12. }   
  13.  
  14. ?>

If You change the value of $ lookingFor to Mary, You will get "You 've got it !" Because Mary is an element in the $ namesArray array.

To count the number of elements in an array, simply use the PHP array function count:


  1.  
  2. $ Countcount = count ($ namesArray);?>

The returned $ count value is 7.

You can add elements at the beginning or end of an array, or use the PHP array function array_merge () to create a new array containing two or more elements in the array, the order of elements is arranged in the specified order. if the original array is out of order, it needs to be re-ordered after merging.

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.