Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

PHP Function With More Than One Value

PHP Function With More Than One Value
 
This article will try to explain how to create a function that can return more than one value, or Returning multiple values from function in PHP. The essence of these functions is the use of arrays and list (); function. Here I will try to give an example function that can separate the first name and last name of a person's name. Create a file named value.php or you can give another name that you want.
 
The contents of the file with:
< ?php
function double_value($fullname)
{
$firstlast = explode(” “, $fullname);
$first_name = $ firstlast[0];
$last_name = $ firstlast[1];
return array($first_name, $last_name);
}
$myfullname = “John Lennon”;
list($myfirstname, $mylastname) = double_value($myfullname);
echo “Full Name : “.$myfullname.”<br>”;
echo “First Name : “.$myfirstname.”<br>”;
echo “Last Name : “.$mylastname ;
?>

The core of its functions :
When a variable used as the contents of the parameter :
double_value ($fullname)
Separate the first and last name by using a space and enter into an array :
$firstlast= explode ("", $fullname);
So that later can be able to access the first name we can use variable $firstlast[0]
and to access last name we can use variable $firstlast[1]
Then do the return value of the form array :
return array ($first_name, $last_name);
With the list() function take two values that shaped an array :
list ($myfirstname, $mylastname) = double_value ($myfullname);
Then show by using echo function :
echo “Full Name : “.$myfullname.”<br>”;
echo “First Name : “.$myfirstname.”<br>”;
echo “Last Name : “.$mylastname ;
That is one example of the algorithm makes the function can return two values.

PHP Function With More Than One Value

PHP File Functions

PHP File Functions

integer fopen (string filename, string mode)

This function is used to open the file before writing or reading the contents of the file.
For example:

Preventing Direct Access In PHP

Preventing Direct Access In PHP Files

To prevent direct access can be used redirect method. Redirect is actually can be exploited when a user has done filling the form, then redirected to a page that contains information that the form has been filled correctly, and other information. This tutorial discusses the more about the PHP file itself. What I mean here is about accessing a PHP file directly.

Automatic Logout Session

Script timer Session, Automatic Log Out

Many things happen if someone has managed to login as a user, and of course this is when the user login will utilize the services of a website, not because of other reasons, such as poor levels of security. There is always an idle period. Idle here means users do not do anything at all on the website, did not move a page, do not enter any input on the form, and nothing cause a web page refresh, in other words a user does not do anything on the website through which he was visiting. 

PHP : Echo or Print

PHP : Using Echo or Print
 
When we write a program using PHP, we often use echo and print commands, but we do not know what is the effects of using echo or print. Sometimes we can be dizzy between two options, use echo or print when you want to display the contents of a variable, or just display text alert than usual as a process that has been done. Echo or Print? Echo or Print? Echo or Print? and so on ... A little confused indeed. In addition to the print and echo, PHP also provides many alternatives for the other syntax.

JavaScript Break Instruction


JavaScript Break Instruction

We can force the loop stops before it’s time for reasons that definite at the beginning of the loop. Break instruction allows to stop a loop (either for the for or while loop). How to use is such as continue instructions, namely the addition of conditional structure in order to stop the loop.

JavaScript Continue


JavaScript Continue Instructions
There are things which should be noticed also, there are times we need to jump on one or more specific values in the loop without stopping the loop itself.
The syntax used here is to continue, and it’s placed in the loop itself, in general we also add conditional structure as a condition so that the syntax is going well.

Javascript For Instructions


Javascript For Instructions
Before talking about the instructions, we talked first about the Loop. Loop is the structure of instructions that can be executed repeatedly as long as the required condition not being met. The most common way of doing loop is to add timer / counter variable (variable increases one unit of value during a one-time loop instructions executed (increment)), Loop will stop if the variable counter has passed the certain value which is used as boundary conditions.

Javascript While Instructions

Javascript While Instructions
While instruction is one of alternative way to run a set of instructions, it is like For instructions as well ..

The syntax of this instruction is as follows:

JavaScript Switch Instructions


JavaScript Switch Instructions

This instruction allows us to test various values of the same variable.
In this way we can do test of various simpler variable value than using if instructions.

JavaScript If Instructions


JavaScript If and If Else Instructions

IF Instruction

The most basic instruction, we can find these instructions in almost every programming language (perhaps with slightly different syntax). This instruction allows us to execute a block of instruction if the condition of the conditions are met.
The syntax of this instruction is as follows:

JavaScript Variable


Working with variables in JavaScript functions
The logic at the time we finished manipulating the variables in the function, and then we get out of the function, then the variable value will be returned to the original value, although we have to change in the function.

JavaScript Variables Placement


JavaScript Variables Placement

Based on the place where we declare a variable, the variable can be accessed from all parts of the program or only in certain parts of the program. At the time of a variable be declared without using the var keyword, or we can call an implicit way, then that variable can be accessed from all parts of the program (all functions in the program can call and use these variables), and we call this variable as global variables.
Conversely, if we declare a variable by explicitly JavaScript (declaring variables using the var keyword), then the possibility of accessing these variables depend the location where it is declared :

Javascript Variables Declaration


Declaring Variables in Javascript

Writing JavaScript variables are very flexible, and not too complicated and strict, so we do not receive error messages too frequently when running the program. For example in JavaScript variable declarations we can do in two ways:

Javascript Variable Data Type


Javascript Variable Data Type

In JavaScript, we do not need to declare the types of variables we will use, otherwise the language of another programming language (which is more advanced) like C or Java. We have to declare in detail whether the variable used is an integer (int), decimal (float), character (char), and other ...

Actually in JavaScript itself, we can only manipulate 4 types of data are:

Javascript Variable


Javascript Variable

Variable
is an object that contains datas, which may be modified during program execution. In JavaScript we can give the name of the variable along that we like, but must meet the following criteria :