Difference between unlink() and unset() function?

unlink() and unset() function in PHP Program -:

Unlink() function is used to delete the files.

Unlink()
  • In PHP unlink() function is used to delete the files. You can delete any file used of unlink() function through the coding.
  • Syntax:- unlink(filename,context)
  • For example-:

    <?php

    $file = “test.php”;

    if (!unlink($file))

    {

    echo (“Error deleting $file”);

    }

    else

    {

    echo (“Deleted $file”);

    }

    ?>

Unset()
  • In PHP unset() function is used to destroys the specified variable. You can destroy the specified variable used of unset() function through the coding.
  • Syntax:- unset (var1, var2)
  • For example-:

    <?php

    $text = “Welcome to PHPCodiing”;

    unset($text);

    if(isset($welcome_text)) {

    echo “My welcome text is: ” . $text . ““;

    } else {

    echo “My welcome text is: empty”;

    }

    ?>

Leave A Comment?

two × three =