PHP nested Array - php sql - Phptpoint.com

PHP nested Array

Best PHP Training with Live Project in Noida Fee is only 7500/-Click here for FREE DEMO.

/ins>

PHP nested array

Syntax

Create a two dimensional numeric array and find the sum.

Output
10 10 10
10 10 10
10 10 10
sum of array : 90

In the above example
Create a variable $arr with value an nested array.
Here at the place of array’s first element there is also an array with three value like
$arr[0][0]=10, $arr[0][1]=10, and $arr[0][2]=10.
at the second index the value are : $arr[1][0]=10, $arr[1][1]=10, and $arr[1][2]=10.
at the 3rd index the value are : $arr[2][0]=10, $arr[2][1]=10, and $arr[2][2]=10.
Now first call all nested array using for loop. first for loop call the three array(row) one by one, inside this loop again call a for loop i.e used to call first array’s all value(columns of row),
print it using echo statement and also make sum ans store inside a variable $s.
So the output will display:
first row’s three column i.e 10 10 10
second row’s three column i.e 10 10 10
Third row’s three column i.e 10 10 10
and the final sum is 90


Create a two dimensional numeric array and find the sum using for-each

Output
10 10 10
10 10 10
10 10 10
sum of array : 90

Two dimensional associative array( user’s name and mobile number)

Output

NameMobile
neeraj342353534
rohit34235
deepak33534

Two dimensional associative array

Display city according to selected country

Output
select country
City

In the above example
first create an array in which multiple index(country) are defined as array, on that array multiple city defined(as column of row).
Now user has to select his country name from select box.
according to selected country, find the city i.e stored on country index using foreach loop.

Multidimensional associative array

Syntax

Output
bihar
North delhi
dwarka

Keep Updating yourself