PHP實現(xiàn)C#山寨ArrayList的方法
更新時間:2015年07月16日 14:35:01 作者:宋勇野
這篇文章主要介紹了PHP實現(xiàn)C#山寨ArrayList的方法,通過一個php自定義類模擬實現(xiàn)C#中ArrayList的功能,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了PHP實現(xiàn)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/>";
}
}
}
希望本文所述對大家的php程序設(shè)計有所幫助。
您可能感興趣的文章:
- C# 沒有動態(tài)的數(shù)組,可以用arraylist或list取代
- C#中Array與ArrayList用法及轉(zhuǎn)換的方法
- 淺析C#中數(shù)組,ArrayList與List對象的區(qū)別
- C#中ArrayList的使用方法
- 解析C#中[],List,Array,ArrayList的區(qū)別及應(yīng)用
- C#檢查指定對象是否存在于ArrayList集合中的方法
- C#查找對象在ArrayList中出現(xiàn)位置的方法
- C#生成隨機ArrayList的方法
- c# ArrayList的使用方法小總結(jié)
- C#中Arraylist的sort函數(shù)用法實例分析
- C#.Net ArrayList的使用方法
- 輕松學(xué)習(xí)C#的ArrayList類
相關(guān)文章
PHP查詢大量數(shù)據(jù)內(nèi)存耗盡問題的解決方法
這篇文章主要為大家詳細(xì)介紹了PHP查詢大量數(shù)據(jù)內(nèi)存耗盡問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
php session實現(xiàn)多級目錄存放實現(xiàn)代碼
這篇文章主要介紹了php session實現(xiàn)多級目錄存放實現(xiàn)代碼,需要的朋友可以參考下2016-02-02
php自定義函數(shù)實現(xiàn)二維數(shù)組按指定key排序的方法
這篇文章主要介紹了php自定義函數(shù)實現(xiàn)二維數(shù)組按指定key排序的方法,通過自定義函數(shù)實現(xiàn)二維數(shù)組按照指定鍵值進行排序的功能,涉及數(shù)組的遍歷與判定相關(guān)操作技巧,需要的朋友可以參考下2016-09-09

