Home php教程 php手册 PHP实现C#山寨ArrayList的方法

PHP实现C#山寨ArrayList的方法

Mar 17, 2017 pm 05:19 PM
arraylist c# php built-in functions

本文实例讲述了PHP实现C#山寨ArrayList的方法。分享给大家供大家参考。具体如下:

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

希望本文所述对大家的php程序设计有所帮助。

相关文章:

详细介绍用C#描述数据结构3:ArrayList的图文代码

js实现ArrayList功能附实例代码

Java集合之ArrayList示例代码分析

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

Random Number Generator in C# Random Number Generator in C# Sep 03, 2024 pm 03:34 PM

Random Number Generator in C#

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles