Make Money Online HTML PHP JAVASCRIPT PHP Array Tutorial in Hindi / Urdu

PHP Array Tutorial in Hindi / Urdu

PHP Array Tutorial in Hindi / Urdu post thumbnail image


PHP Array Tutorial

An array is a data structure that allows you to store multiple values in a single variable. The values in an array can be accessed by their numerical index, or by using a key.

Creating an Array

To create an array in PHP, you use the array keyword followed by the name of the array and the values you want to store in it.

For example, the following code creates an array called fruits with three values:

$fruits = array(“apple”, “orange”, “banana”);

You can also create an array with a single value by using the array() function.

For example, the following code creates an array with the value “Hello”:

$fruits = array(“Hello”);

Accessing Array Values

To access the values in an array, you use the numerical index of the value you want to access.

For example, the following code prints the value “apple” from the fruits array:

echo $fruits[0];

You can also access array values by using their key.

For example, the following code prints the value “Hello” from the fruits array:

echo $fruits[“Hello”];

Adding and Removing Array Values

You can add new values to an array by using the array_push() function.

For example, the following code adds the value “grape” to the fruits array:

array_push($fruits, “grape”);

You can remove values from an array by using the array_pop() function.

For example, the following code removes the value “apple” from the fruits array:

array_pop($fruits);

The following code removes the last value from the fruits array:

array_pop($fruits);

Related Post