Created
September 22, 2010 22:32
-
-
Save radiosilence/592709 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* An attempt to make arrays into objects, I guess. | |
*/ | |
namespace Core; | |
class Arr { | |
private $elements = array(); | |
public function __construct() { | |
foreach( func_get_args() as $item ){ | |
$this->append( $item ); | |
} | |
} | |
public function append($item) { | |
$this->elements[] = $item; | |
} | |
public function extend($items) { | |
if(!is_array($items)) { | |
$items = array($items); | |
} | |
foreach($items as $item){ | |
$this->elements[] = $item; | |
} | |
} | |
public function insert($position,$item) { | |
$tail = array_splice($this->elements, $position); | |
$this->elements[] = $item; | |
$this->elements = array_merge($this->elements, $tail); | |
} | |
/** | |
* Counts the values | |
* @return int | |
*/ | |
public function count($value) { | |
$counts = array_count_values($this->elements); | |
return $counts[$value]; | |
} | |
public function __toArray() { | |
return $this->elements; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment