PHP optionale Funktionsargumente mit Array. Wie codiere ich / Besser codiere ich?

Ich bin sicher, dass es ein besseres gibt. Jede Hilfe wird sehr geschätzt.

Ich möchte ein Array an eine PHP-Funktion übergeben, die das Argument enthält und alle Argumente sind optional. Ich benutze Code Ignitor und bin kein Experte. Unten ist, was ich bisher verwendet habe:

function addLinkPost($postDetailArray) {

    if (isset($postDetailArray['title'])) {
        $title = $postDetailArray['title']; }
    else {
        $title = "Error: No Title";
    }

    if (isset($postDetailArray['url'])) {
        $url        = $postDetailArray['url'];
    } else {
        $url        = "no url";
    }
    if (isset($postDetailArray['caption'])) {
        $caption    = $postDetailArray['caption'];
    } else {
        $caption    = "";
    }
    if (isset($postDetailArray['publish'])) {
        $publish    = $postDetailArray['publish'];
    } else {
        $publish    = TRUE;
    }
    if (isset($postDetailArray['postdate'])) {
        $postdate   = $postDetailArray['postdate'];
    } else {
        $postdate   = "NOW()";
    }
    if (isset($postDetailArray['tagString'])) {
        $tagString  = $postDetailArray['tagString'];
    } else {
        $tagString = "";
    }

Antworten auf die Frage(7)

Ihre Antwort auf die Frage