PHP implements the C # shanzhai ArrayList method,

Source: Internet
Author: User

PHP implements the C # shanzhai ArrayList method,

This example describes how PHP implements the C # shanzhai ArrayList. Share it with you for your reference. The details are as follows:

Class ArrayList {public $ length; public $ name; public $ my_array; function _ construct () {$ this-> my_array = Array ();} public function Add ($ element) {array_push ($ this-> my_array, $ element);} public function get_Length () {$ this-> length = count ($ this-> my_array ); return $ this-> length;} public function get_Element ($ key) {if (array_key_exists ($ key, $ this-> my_array )) {echo $ this-> my_array [$ key];} else {echo "No such element" ;}} public function list_array () {foreach ($ this-> my_array as $ value) {echo $ value; echo "<br/>" ;}} public function Delete ($ key) {if (array_key_exists ($ key, $ this-> my_array) {$ this-> my_array [$ key] = null;} else {echo "No such element ";}} public function erase_number () {$ pattern = "/[0-9]/"; foreach ($ this-> my_array as $ value) {if (eregi ($ pattern, $ value) {$ value = null ;}} foreach ($ this-> my_array as $ value) {echo $ value; echo "<br/> ";}} public function erase_char () {$ pattern = '/a-zA-Z/'; for ($ I = 0; $ I <count ($ this-> my_array)-1; $ I ++) {if (eregi ($ pattern, $ this-> my_array [$ I]) {$ this-> my_array [$ I] = null ;}} foreach ($ this-> my_array as $ value) {echo $ value; echo "<br/> ";}}}

I hope this article will help you with php programming.

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.