This article mainly introduces PHP's method of implementing C # shanzhai ArrayList, and implements the ArrayList function in C # through a php custom class simulation, which has some reference value, for more information, see
This article mainly introduces PHP's method of implementing C # shanzhai ArrayList, and implements the ArrayList function in C # through a php custom class simulation, which has some reference value, for more information, see
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"
";}} Public function Delete ($ key) {if (array_key_exists ($ key, $ this-> my_array) {$ this-> my_array [$ key] = null ;} else {echo "This element does not exist" ;}} 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"
";}} Public function erase_char () {$ pattern = '/a-zA-Z/'; for ($ I = 0; $ I 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"
";}}}
I hope this article will help you with php programming.
,