A pointer to an array in the PHP learning record array

Source: Internet
Author: User

Unshift add an element to the array header, push adds an element to the end of the array, shift deletes the first element of the array, and the pop deletes the last element of the array:

<?php  $item =array (' Apple ');//Add an element Array_unshift ($item, ' banana ') at the top of the array, Print_r ($item);//Add an array at the end of the array Array_push ($ Item, ' Pineapple ');p rint_r ($item);//delete the first element Array_shift ($item);p rint_r ($item);//delete last element Array_pop ($item);p Rint_r ($item) ;? >

Array_rand randomly removes the subscript for the array:

<?php $item =array (' Apple ', ' banana ', ' pineapple ');//Use a variable to receive a random array of subscripts, 1 for 1 elements of subscript $a=array_rand ($item, 1); Echo $item [$a]; ><?php $item =array (' Apple ', ' banana ', ' pineapple '), $a =array_rand ($item, 2), Echo $item [$a [0]];echo $item [$a [1]];? >

Current fetch element generally refers to the first element next gets the element of the current next bit reset re-acquires the element from the first start prev backwards a array_count_values (); Number of repetitions of the value of a statistic array extract () Assign a value to a string key after it has been changed to a variable.

<?php $username =array (' Ronaldo ', ' Lionel Messi ', ' West ');//Gets the current element, Echo ($username);//Gets the next element echo next ($username);// Resets the current element echo reset ($username); Echo next ($username);//Reverse an echo prev ($username); ><?php//subscript corresponds to the number of repetitions $item =array (' a ' = ' = ' Apple ', ' b ' = ' banana ', ' C ' + ' cantaloupe ', ' d ' and ' = ' apple ');//Gets the number of elements echo sizeof ( $item);p Rint_r (Array_count_values ($item));//Copy the value of key into a variable and extract ($item); Echo $a; >

  

A pointer to an array in the PHP learning record array

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.