0

私は 1 つの解決策 (以下に投稿します) を思いつきましたが、より良い、よりコンパクトな方法があるかどうか疑問に思っていました。

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);
}
4

1 に答える 1