You are currently viewing What is PHP goto Statement | Explained
  • Post category:PHP

What is PHP goto Statement | Explained

PHP goto Statement

In this article, we will see what is php goto statement.

PHP goto statement

It transfers the control to the specified label. A text followed by a (:) symbol indicates a label.

Ex; beginning:, end:, etc.

Syntax :

goto labelText;

Example:

<?php
goto fullName:

firstName:
echo "John";
goto end;

lastName:
echo "Wesely";
goto end;

fullName:
echo "John Wesely";

end:
?>

/* Output:
John Wesely
*/

Steps:

  1. In the above code, we use the “goto” keyword then we call the label “fullName”.
  2. We have created three labels namely “firstName”, “lastName”, and “fullName”. “goto end” keyword should be placed after creating each label.
  3. After creating all the labels, we use the “end” keyword for ending the labels.

 

Leave a Reply