Hi friends we are going to next part.please go to the line number 13 of our registration.php page

1
2
3
4
5
6
7
8
9
$details = array(
                        "vchr_name"     =>  $name,
                        "vchr_house"     =>  $house,
                        "vchr_street"     =>  $street,
                        "vchr_city"     =>  $city,
                        "vchr_district" =>  $dist,
                        "vchr_state"     =>  $state,
                        "vchr_phone"    =>  $phone
                 );

This is an array in php.What is array?.

Hope you all know about arrays, even though I’ll give you a small idea about arrays in php. For saving data now we know about variables in php if we have a situation that we want to save many values, How can we save it?. We can save it by using variables $number0, $number1, …, and $number99. Is this a possible method to implement?. So we are using arrays. Instead of using individual variables, such as $number0, $number1, …, and $number99, we are using an array variable such as $numbers and use numbers[0], numbers[1], and …, numbers[99] to represent individual variables. A specific element in an array is accessed by an index.Please look at the image below it may useful to understand more about arrays.

premjith array

In PHP, there are three types of arrays:

  • Indexed arrays (Single dimensional) – Arrays with numeric index
  • Associative arrays – Arrays with named keys
  • Multidimensional arrays – Arrays containing one or more arrays

I’ll give you one sample example of each type of array, from these please try to understand the storage and working.

1
$vehicle=array("Car","Bike","Jeep");

The above one is a single directional array or indexed array. we can access the value of array named $vehicle like this.$vehicle[0] will pointing to the value ‘Car’ in the array. and we can also save the value to array like this $vehicle[0] = ‘Car’. We are using loops to retrieve the information from array.It will be clear to you while we are going forward.To get a beginning please consider the code below

1
2
3
4
5
6
7
8
9
<?php
 
$arrlength=count($vehicle);
for($i=0;$i<$arrlength;$i++)
  {
	  echo $vehicle[$i];
	  echo "<br>";
  }
?>

Do it your self and experience the output.Look at the below code to know about associative array.Here each set of value saved ad key value pair.

1
2
3
4
<?php
$age=array("Prem"=>"26","Jithu"=>"25","premjith"=>"43");
echo "premjith is " . $age['premjith'] . " years old.";
?>

Now we are going to multidimensional arrays.Multidimensional array in php is array containing one or more arrays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    $Vehicles = array (
      		"Car"=>array(
      							"Benz",
      							"BMW",
      							"Toyota"
      						),
      		"Bus"=>array(
      							"Ashok layland",
                                                        "Tata"
      						),
      		"Jeep"=>array(
      							"Mahindra",
 
      						)
	);

Here ‘Vehicle’ is an array and ‘Car’,’Bus’,’Jeep’ are arrays inside the vehicle array. It will be more understandable to us while we are moving.

I hope we can stop the array matter here. Then go to our next line in registration.php

1
2
3
4
5
6
7
8
 $table = "tbl_registration";
        $register=$obj_reg->insert($details, $table);
                if($register){
                    echo "<script> alert('Registered Successfully');</script>";
                    header( 'Location:index.php' ) ;
                }else{
                    echo "<script> alert('Registration Failed');</script>";
                }

Here a variable ‘$table’ assigns a our table name. after that calling the insert function in our class using the above declared object ‘$obj_reg’ and saving the out put of the function call to the variable ‘$register’. The value of the variable register will be Boolean. That is true or false. If the value is true we will get an alert message of success other wise failure. We can discuss the remaining portion later.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

23 − = 20