|
本文实例讲述了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 "
";
}
}
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 "
";
}
}
public function erase_char()
{
$pattern='/a-zA-Z/';
for($i=0;$imy_array)-1;$i++)
{
if(eregi($pattern, $this->my_array[$i]))
{
$this->my_array[$i]=null;
}
}
foreach ($this->my_array as $value)
{
echo $value;
echo "
";
}
}
}
希望本文所述对大家的php程序设计有所帮助。
您可能感兴趣的文章:C# 没有动态的数组,可以用arraylist或list取代C#中Array与ArrayList用法及转换的方法浅析C#中数组,ArrayList与List对象的区别C#中ArrayList的使用方法解析C#中[],List,Array,ArrayList的区别及应用C#检查指定对象是否存在于ArrayList集合中的方法C#查找对象在ArrayList中出现位置的方法C#生成随机ArrayList的方法c# ArrayList的使用方法小总结C#中Arraylist的sort函数用法实例分析C#.Net ArrayList的使用方法轻松学习C#的ArrayList类
|
|