我想出了一个解决方案(我将在下面发布),但我想知道是否有更好、更紧凑的方法?
function removeImage($id) {
$index;
for ($i = 0; $i <= count($this->_images); $i++) {
if ($this->images[$i] == $id) {
$index = $i;
break;
}
if ($i == count($this->_images)) {
throw new Exception("No image with this ID found.");
}
}
unset($this->_images[$index]);
$this->_images = array_values($this->_images);
}