Skip to content

Instantly share code, notes, and snippets.

@Kedrigern
Created October 27, 2014 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kedrigern/a627254ccf9fdf3f62a8 to your computer and use it in GitHub Desktop.
Save Kedrigern/a627254ccf9fdf3f62a8 to your computer and use it in GitHub Desktop.
my_array_splice
#!/usr/bin/php
<?php
class A {
public $a;
public function __construct($a) {
$this->a = $a;
}
};
function my_array_splice(&$arr, $start, $end) {
for($i = $start; $i <= $end; $i++) {
unset($arr[$i]);
}
}
$arr = [];
$arr[] = new A('a');
$arr[] = new A('b');
$arr[] = new A('c');
$arr[] = new A('d');
$arr[] = new A('e');
$arr[] = new A('f');
print_r($arr);
$start = 1; // b
$end = 3; // d
//array_splice($arr, $start, $end - $start);
my_array_splice($arr, $start, $end - $start + 1);
print_r($arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment