What Is an Array?

An array is a unique type of variable that has the capacity to store multiple values under a single name. By using an index number or name, you can retrieve the items from the array.

Types of Array

1) Arrays with indexing

2) Associative Arrays

Arranged in Index Forms

Every item in an indexed array has an index number.

Index 0 is assigned to the first item by default, item 1 to the second, and so on.

As an illustration.

$fruits = array ( “Banana”, “Grapes”, “Mango”);

Mangos have an index of 0, bananas of 1, and grapes of 2.

By utilizing a loop, we can print the array.

For instance

$fruits = array ( “Banana”, “Grapes”, “Mango”);

foreach ($fruits as fruit)  {

echo “$fruit”;

}

Arrays predefined functions:

array()

array_merge()

array_pop()

array_push()

array_unshift()

count()

range()

sort()…etc

An Associative Array

Associative arrays are arrays that utilize named keys that are assigned to them.

For instance, $fruits = array(“name”=>”apple”, “color”=>”red”, “price”=>100);

To obtain a specific element, we can type:

fruits[‘name’] in $fruits;

Additionally, we are able to modify the specific value of an element such as

$fruits[‘name’] =”ORNAGE”;

What is String?

Strings are collections of characters.

PHP allows us to write strings either in single quotes (”) or double quotes (“”).

As an illustration,

“Strings” or “String-like”

Dot (.) can be used to concatenate strings.

$x = “HELLO”;

$y = “Strings”;

$z = $x. $y;

Functions of Strings:

strlen()

substr()

trim()

strtoupper()

strtolower()

count_chars()…etc