Home > Backend Development > PHP Tutorial > PHP method to implement C# copycat ArrayList, _PHP tutorial

PHP method to implement C# copycat ArrayList, _PHP tutorial

WBOY
Release: 2016-07-13 09:46:23
Original
820 people have browsed it

How to implement C# copycat ArrayList in PHP,

This article describes the method of implementing C# copycat ArrayList in PHP. Share it with everyone 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 "没有这个元素";
  }
 }
 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 "没有这个元素";
  }
 }
 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/>";
  }
 }
}

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1033492.htmlTechArticleHow to implement C# copycat ArrayList in PHP. This article describes the method of implementing C# copycat ArrayList in PHP. Share it with everyone for your reference. The details are as follows: class ArrayList{ public $length;...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template