To declare a string array in PHP, you can use the array() function or the square bracket syntax with string elements.
In this example,
$stringArray
using array() function with predefined string values.<?php
$stringArray = array("Hello", "World", "PHP");
echo "String Array: ";
print_r($stringArray);
?>
String Array: Array ( [0] => Hello [1] => World [2] => PHP )
In this example,
$emptyStringArray
using the array() function without any elements.<?php
$emptyStringArray = array();
echo "Empty String Array: ";
print_r($emptyStringArray);
?>
Empty String Array: Array ( )
In this tutorial, we learned How to Declare a String Array in PHP language with well detailed examples.