Skip to content

Instantly share code, notes, and snippets.

@radiosilence
Created September 22, 2010 22:32
Show Gist options
  • Save radiosilence/592709 to your computer and use it in GitHub Desktop.
Save radiosilence/592709 to your computer and use it in GitHub Desktop.
<?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