Free cookie consent management tool by TermsFeed Generator PHP break and continue | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
PHP break and continue

PHP break and continue

Last Updated on Mar 21, 2023

We have already talked about loops. Inside the loop we can use 2 words

  • break
  • continue

Let’s see what they mean and what they do.

Break

We are telling php to jump out of the loop completely and execute the rest of the code.

For example we're looking for a value inside an array. we'll check each value inside the array to see if it is what we’re looking for. When we find our value we don’t care about the rest. so we want to jump completely out of the loop and execute the rest of the code.

<?php
$names = ['Vitto','Simon','Pratham','Hassib','Thomas','Tom'];

foreach($names as $name){
    if($name == 'Pratham'){
        // found him. there is no need to continue
        break;
    }
}
// execute the rest of the code

Continue

We are telling php to skip the current iteration of the loop and execute the next one.

For example we want to echo some of the values inside an array. So if the value doesn’t have what we specified, we'll to go to the next iteration. We don’t want to completely end the loop.

$numbers = [50,250,5421,3,756,93,43];

foreach($numbers as $number){
    // skip the numbers that are divisible by 3
    if($number % 3 == 0){
        continue;
    }
    echo $number;
}

https://youtu.be/F8Z31bQ-1x8

Conclusion

Now you know about break and continue in PHP.

I recommend you to open a PHP files and write a loop. try the words continue and break and see what happens.

If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!

Key takeaways

  • continue in a loop PHP
  • break in a look PHP

Category: programming

Tags: #php

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

Ultimate guide to RESTFul API Versioning in PHP Laravel: 2 solutions
Feb 15, 2023 programming

Ultimate guide to RESTFul API Versioning in PHP Laravel: 2 solutions

API versioning is what you need if you want to change the behavior of your API or the structure and format of requests and responses. ...

17 Min Read Read More
PHP function
Mar 21, 2023 programming

PHP function

Today we are going to learn about functions in PHP. Functions are very important because they can help you divide your application in small bites that can be handled with a function. ...

10 Min Read Read More
PHP execution time
Feb 15, 2023 programming

PHP execution time

Today we are going to talk about calculating execution time in PHP. Sometimes it’s a good idea to calculate the execution time of your functions and script as a whole. ...

3 Min Read Read More
PHP Beginner to Advanced 2025: The Complete Guide to Mastering PHP and Building Modern Web Applications
Jul 17, 2025 programming

PHP Beginner to Advanced 2025: The Complete Guide to Mastering PHP and Building Modern Web Applications

PHP is often called the engine room of the modern web. Despite debates about newer technologies like Node.js, Go, or Python’s Django, PHP has remained a consistent favorite among developers. In fact, as of 2025, PHP powers over 75% of all websites that use a known server-side programming language. ...

9 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...