1. Computing & Technology

Discuss in my forum

Skipping over chunks of code in PHP using Goto

By , About.com Guide

See More About:
You can skip over chunks of code in PHP using goto. This is not a function so it does not require parenthesis, and it only works if you have php 5.3 or later. In our example below we will echo a line, but it will not output anything if we execute the PHP, because it is in the section of code we are skipping.

<?php
goto a;
echo 'This will be skipped';

a:
echo 'Why hello!';
?>

If you run this code you will only see "Why hello!" and not the other line we echo because it is in the section of code that we skipped between goto and the mark we were searching for.

©2012 About.com. All rights reserved.

A part of The New York Times Company.