What is an Array?
Array is a variable that special , that can hold more than one or more value at a the same time.If you have a the list of somethings (a list of animal names, for example), storing the animal in single variables could look like this:
$animal1 = "cow";
$anima2 = "cat";
$anima3 = "dog";
See the Session functions of documentation for more information on how to this is used. An associative array is containing session variables available to the current script.
This Code testing Array Session in php.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if(isset($_POST['btnset'])){
$data_form[] = array(
"fname" => $_POST['fname'],
"lname" => $_POST['lname'],
"sex" => $_POST['sex'],
"age" => $_POST['age'],
"phone" => $_POST['phone'],
"address" => $_POST['address']
);
$_SESSION['form'] = $data_form;
}else if(isset($_POST['btnclear'])){
if(isset($_SESSION['form'])){
unset($_SESSION['form']);
}
}
function form_val(){
if(isset($_SESSION['form'])){
$usercart=$_SESSION['form'];
/*foreach ($usercart[0] as $key => $item)
{
echo'<br>'.$usercart[0][$key];
}*/
return $usercart;
}else{
return false;
}
}
?>
<form method="post">
<?php $val=form_val(); ?>
fname<input type="text" name="fname" value="<?php echo $val[0]['fname'];?>" />
lname<input type="text" name="lname" value="<?php echo $val[0]['lname'];?>" />
sex<input type="text" name="sex" value="<?php echo $val[0]['sex'];?>" />
age<input type="text" name="age" value="<?php echo $val[0]['sex'];?>" />
phone<input type="text" name="phone" value="<?php echo $val[0]['phone'];?>" />
address<input type="text" name="address" value="<?php echo $val[0]['address'];?>" />
<input type="submit" value="Set" name="btnset" />
</form>
<form method="post">
<input type="submit" value="Clear" name="btnclear" />
</form>
<form method="post">
<input type="submit" value="Other" name="ss" />
</form>
</body>
</html>
**** how to detect browser in php code
No comments:
Post a Comment