knowledgediarybd.com

Your Virtual Knowledge Campus

PHP array Declaration

php arrayPHP array Declaration .PHP Array  are  Special kind of variable  in PHP programming.

PHP array that can hold a number of values on a single variable whereas other variable can hold only one value.

That is an  important fact to use an array In PHP Programming.

Dear learner here you can learn details about PHP array,How to declare it?,How to use it?.

How a  PHP array work ?:

At First a  PHP array holds a number of values on a single variable & each values in an array has own index number.We can use array values by calling index number of value.

For Example:

$player[0]=”Sakib “;

$player[1]=”Nasir Hossain”;

$player[2]=”Tamim”;

Types Of PHP array:

There are three kinds of array in PHP:

1.Numerical arrays: An array that can hold Numerical values & Numeric    index.

2. Multidimensional arrays: That can represent one or more arrays.

3.Associative arrays:  Is an array where  every  key  id is associated with  a value

1.Numerical arrays:

An array that can hold Numerical values & Numeric   index.

There are  two ways to defined  a numerical arrays.

         1.>> Number one  where index number are automatically assigned.

For Example:  $palayer=array(“Sakib”,”Nasir Hosasin”, “Tamim”);

2.>> Number Two Where index number can be assigned Manually.

For Example:

$player[0]=”Sakib “;

$player[1]=”Nasir Hossain”;

$player[2]=”Tamim”;

Numerical array with PHP Code:

<html>
<head>
            <title>Wel come to Knowledgediarybd.com</title>
</head>
<body>
<?php
$player[0]="Sakib";
      $player[1]="Nasir Hossain";
  $player[2]="Tamim";
echo $player[0] . " & " . $player[2] .  " are two Top Order Batman's Of Bangladesh Cricket Team.";
?>
</body>
<html>

The output of the above php Code :

Sakib & Tamim are two Top Order Batman’s Of Bangladesh Cricket Team.

2. Multidimensional arrays:

That can represent one or more arrays.

Example of Multidimensional arrays:

$player_1 = array (75,98,100);
$player_2 = array (50,85,300);
$player_3 = array (25,105,226);

$multidimensional_array = array ($player_1, $player_2, $player_3);

Here, $multidimensional_array is now a 2-dimensional array.

If we run this code on a browser then we can see that.
print {$multidimensional_array [1,2]};

output would be look like below:

300

3. Associative arrays: 

Is an array where  every  key  id is associated with  a value.

By using an associative arrays you can use the value as key & assign values to them.

For Example:

$player_rurs = array(“Sakib”=>100, “Nasir hossain”=>70, “Tamim”=>134);
That is equivalent to the following:

$player_rurs[“Sakib”] = 100;
$player_rurs[“Nasir hossain”] = 70;
$player_rurs[“Tamim”] = 134;

Associative arrays with PHP Code:

<html>
<head>
<title>Wel come to Knowledgediarybd.com</title>
</head>
<body>
<?php
$player_rurs["Sakib"] = 100;
    $player_rurs["Nasir hossain"] = 70;
$player_rurs["Tamim"] = 134;
echo "Sakib al Hassan Scored  " . $player_rurs["Sakib"] . " run in this match.";
?>
</body>
</html>

 The out put of the above code  look line below:

Sakib al Hassan Scored 100 run in this match

Related Post:

knowledgediarybd.com © 2017
shares