2.1 Creating Functions
In programming there is also a term function / function. function makes programming process can be more efficient because certain actions can be written in one function that will be called if required. A function can receive the value, process it and then returns the new value. Physically, the function block code which can be called later.
<? php
mentioned function ($ name) {
$ result = "Your name is". $ name;
Print $ result;
}
print mentioned ("Irfan Gonzales");
?>
If run in the browser, it looks to be like this.
2.1.1 Appearance with the function name |
In the above functions are variable. Variables are placed in in function of the local scope, meaning that can not be accessed outside these functions. In the function, you also can not access other functions in outer.
<? php
$ name = "Rafael Nadal";
mentioned function () {
print "Your name is $ name <br />";
}
mentioned ();
?>
If the above code is executed, it will not be displayed $ name considering the variables declared outside the function.
2.1.2 Variables are placed outside the function will not be visible |
A programming language generally has a variable of type array. Array (in Indonesian is often translated as array) is a variable which contains other values.
To allocate the value of the array to a particular variable, you could be using many methods, one of which is as follows:
$ humans = array (
"name" => "Stephanie",
"age" => 25,
);
To access, you can use a number or name index, for example:
print $ humans ['name];
Array itself has many variations to define. The First by allocating automatically index (where index
The first is the number 0) with the following code:
$ car = array ("Daihatsu", "Proton", "Toyota", "Citroen");
The second way is to allocate index manually:
$ cars [0] = "Daihatsu";
$ cars [1] = "Proton";
$ cars [2] = "Toyota";
$ cars [3] = "Citroen";
The following code example defines an array, and then access the value the array.
<? php
$ food [0] = "Pecel";
$ food [1] = "Rojak";
$ food [2] = "Petis";
$ food [3] = "Sate";
$ food [4] = "Rendang";
echo "I like to eat". $ food [0] "And" $ food [4] ". Everything mak nyuss.";
?>
If we open it in a browser, the above array to be as follows.
2.2.1 The page access code in the page array |
0 komentar:
Posting Komentar