Print Numbers from 1 to N without using loop in PHP


Welcome back to, today we will learn how to print 1 to N number without using any type of loop.
In this tutorial we print 1 to N number with the help of some php functions like range() and array_walk.
1 to N without using loop in PHP
The range() function is used to create an array of elements of any kind such as integer, alphabets within a given range(from low to high) i.e, list’s first element is considered as low and last one is considered as high.
syntax of range function is like

array range(low, high, step)

It returns an array of elements from low to high.
for example

$numbers = range(0, 100);

The array_walk() function apply a user defined function to every element of an array. The user-defined function takes array’s values and keys as parameters.

$array = range(1, 100);
array_walk($array, function ($value) {
echo "$value";


and the another way to print 1 to N number is

function print_number($number) {
if($number > 100) {
} else {
echo "$number";
echo "<br/>";