【PHP】unset、isset、header

Sep 7, 2020 PHP

I will summarize what I learned about PHP as a memorandum.

#unset A function that deletes a defined variable assignment. It is also possible to delete arrays that are no longer needed. For example, if you want to delete an element in an array, write it like this.

$ ary = array (0,1,2,3,4);
unset ($ array [3]);

If you define it as above, you can delete the 4th element “3”.

#isset It can be a variable as an argument and returns true if the variable is set to a value. Returns false if no value is set.

For example, you can perform branch processing like the following code.

if (isset (x)) {
If x is set to a value
}
else else
{
If x is not set to a value
}

It is also possible to perform actions such as skipping to the specified path when the value is posted to the session.

#header This is a function that sends HTTP headers. It is used when you want to skip to a specified path after completing a certain process.

If you define it as below, you can skip to the file with the specified path.

<? php
 Header ('Location: ../index.php');
Exit;
?>

In the above example, when the header function works, it will jump to index.php. It can be used when you want to branch files.

#Reference URL https://techacademy.jp/magazine/11410 https://techacademy.jp/magazine/12288 https://techacademy.jp/magazine/11609