To declare an integer array in PHP, you can use the array() function or array shorthand syntax.
In this example,
$numbers
with predefined values using the array() function.<?php
$numbers = array(1, 2, 3, 4, 5);
echo 'Integer Array: ';
print_r($numbers);
?>
Integer Array: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
In this example,
$emptyArray
using the array shorthand syntax.<?php
$emptyArray = [];
echo 'Empty Integer Array: ';
print_r($emptyArray);
?>
Empty Integer Array: Array ( )
In this tutorial, we learned How to Declare an Integer Array in PHP language with well detailed examples.