Created
October 27, 2014 15:38
-
-
Save Kedrigern/a627254ccf9fdf3f62a8 to your computer and use it in GitHub Desktop.
my_array_splice
This file contains 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
#!/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