Ads 468x60px

Pages

Jumat, 16 Agustus 2013

Array in PHP

In many Web applications, often we need a variable that can store multiple values at once in an organized manner, so that next time we can recover these values with ease and in a regular and well organized. No, not the database that I mean, as I was talking to a variable, and the database is not a variable. Why is this so important? Because in most cases we only need a store of value as well-organized, and the database is very expensive to do so. Think about connections, queries, and so on that will slow down the process when we use the database. This is where we need the array, a type of variable that can store multiple values at once even in different types of well-organized. Thus, in any programming language including PHP course you will always find an array as one of the types of variables. array is powerful.

What and Why

Arrays in PHP are a special type of variable, because the array we can access a set of values using a single variable name. The mechanism is arranged in the form of accessing the mapping of a set of values to a set of keys or indices. For example, the array variable $programer can map 1, 2 and 3 respectively to the "aaaaaa" "bbbbbb" and "cccccc, so it can be expressed as:

$programmer[1] = "aaaaaa";
$programmer[2] = "bbbbbb";
$programmer[3] = "cccccc";

where the expression 1, 2 and 3 is the index, while "aaaaaa" "bbbbbb" and "cccccc" are values.

$programmer_1 = "aaaaaa";
$programmer_2 = "bbbbbb";
$programmer_3 = "cccccc";
$cracker_1 = "dddddd";
$cracker_2 = "eeeeee";
$cracker_3 = "ffffff";

If we needed to print six of these data, it can be used in the following ways:

print "Name Programmer No 1: $programmer_1 <br>";
print "Name Programmer No 2: $programmer_2 <br>";
print "Name Programmer No 3: $programmer_3 <br>";
print "Name Cracker No 1: $cracker_1 <br>";
print "Name Cracker No 2: $cracker_2 <br>";
print "Name Cracker No 3: $cracker_3 <br>";

This method may be effective but unfortunately far from efficient. Why? because if the amount of data programmer and cracker on top of up to tens or even hundreds, then imagine how much you have to type the command. Not to mention, the webserver must do the parsing of hundreds of lines that will slow down the whole process. With an array, you can do better on the effective and efficient. 900 For example, a data programmer and cracker. How short, simple, but powerful. In addition, many PHP functions to manipulate arrays make the variable type is very helpful to our work in creating web applications. You simply perform the iteration as follows:

for ($k=0;$k<900;$k++)
{
print "Nama hacker ke $k: $hacker[$k] <br>";
}

for ($k=0;$k<900;$k++)
{
print "Nama cracker ke $k: $cracker[$k] <br>";
}

We will discuss some PHP functions to manipulate arrays in the next section.

Related Posts by Categories

0 komentar:

Posting Komentar