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

the ultimate guide to Git: learn everything you need in less than 1 hour
Nov 28, 2022 programming

the ultimate guide to Git: learn everything you need in less than 1 hour

Here is everything you need to know about git in a series of short question and answers. ...

11 Min Read Read More
PHP Arrays
Mar 21, 2023 programming

PHP Arrays

Today we are going to learn about arrays in PHP. Array is a datatype that can hold more than one value so instead of having multiple variables you can hold all those values in one variable. ...

9 Min Read Read More
PHP Array Combine
Feb 14, 2023 programming

PHP Array Combine

Today we are going to talk about array combine in PHP. Array combine is another useful array function that creates an array by using one array for keys and another for its values. ...

3 Min Read Read More
AngularJS Beginner to Advance 2025: The Complete Guide for Modern Web Developers
Jul 18, 2025 programming

AngularJS Beginner to Advance 2025: The Complete Guide for Modern Web Developers

In today’s web development landscape, AngularJS may no longer dominate headlines, but it still powers countless legacy applications. Many organizations—especially in finance, healthcare, and enterprise software—rely on AngularJS systems that require ongoing maintenance and enhancements. ...

43 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 ...