7. Variable Variable and Static Variable

Variable Variable:

<?php
	$bd="Bangladesh";
	$$bd="Dhaka";
	echo $Bangladesh;
?>

Static variable:Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. A static variable will not lose its value when the function exits and will still hold that value should the function be called again

<?php
	function myTest() {
		static $x = 0;
		echo $x;
		$x++;
	}
	myTest();
	myTest();
	myTest();
?>

6. Variable Scope

  1. File to File Variable Scope
  2. Function to function variable scope

File to file variable scope:
Have 4 Functions (include, include_once, require, require_once). Where the difference between is include & require: if you have used include function and include file path didn’t match. You will see a warning msg. but next code is executed or run. if you have used require function and require file path didn’t match. You will see an error msg. but next code is not executed or run.

Variable scope with function: If you want to access outer variable of the function. you have  to use global function.

<?php
	/*$var=10;
	function ajob(){
		global $var;
		return $var;
	}
	echo ajob();
	*/
	$a=5; // This is global variable
	function test(){
		$a =6; // This is local variable
		return $a+$GLOBALS[‘a’];
	}
	echo test();
?>

5. A String literal different ways

  1. Single quoted
  2. Double quoted
  3. Nowdoc syntax
  4. Heredoc syntax

Single quoted & double quoted:

<?php
	
	echo 'They don\'t know how it\'s possible';
	echo "<pre>";
	
	$karim="student";
	$age = 20;
	echo 'karim is a $karim, he is $age years old';
	echo "<pre>";	
	echo "karim is a $karim, he is $age years old";

	// single quoted ' ' that is show only variable
	// double quoted " " that is show only value

?>

1.Nowdocs are to single-quoted strings.
2.Heredocs are to double-quoted strings.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nowdoc & heredoc</title>
</head>

<body>
<?php 
$name = "Ataur rahman";
$email = "ataur@gmail.com";
$mobile = "667688754";
$address = "Dhaka, Bangladesh";

echo <<< 'test'

<table width="403" border="1">
  <tr>
    <td width="162">Name</td>
    <td width="225">$name</td>
  </tr>
  <tr>
    <td>Email</td>
    <td>$email</td>
  </tr>
  <tr>
    <td>Mobile</td>
    <td>$mobile</td>
  </tr>
  <tr>
    <td>Address</td>
    <td>$address</td>
  </tr>
</table>

test;
?>
</body>
</html>

4. PHP Loose type and Type Casting

PHP Loose type:

echo “<pre>”;
var_dump($v=”profile”);
var_dump($v=6);
var_dump($v=6.5);
var_dump(false == array());
var_dump(true == array());

Data type changing with casting:

$a=6.5;
echo (integer) $a;      //Run time type casting, only this line type cast
echo $a;
echo $a;

but if you permanently type cast. So you have to do use settype function

Data type changing with settype():

$a=9.6;
settype($a, “integer”);
echo $a;
echo $a;
echo $a;               //Result not change

3. PHP Data Type

PHP Data Type: 2 data type

1. Scaler Data type:

Type

Description

Example values

integer  A whole number (32 bit) 15, -36
float  A floating point number (32 bits with fraction) 9.58, -65.58
string  A sequence of characters "World", "abc123@#$"
unicode  A sequence of Unicode characters "Hello", "abc123@#$"
binary  A sequence of binary (non-Unicode) characters "Hello", "abc123@#$"
boolean  Either true or false true, false

2. Compound Data Type:

Array : Can hold multiple values indexed by numbers or strings

Object: Can hold multiple values (properties), and can also contain methods

2. How much PHP Tags / Syntax? Echo and print?

<SCRIPT LANGUAGE='PHP'> </SCRIPT>

<% %> [enabled asp_tags php.ini setting]

<?php ?> [This is standard Tags]

<? ?> [enabled short_open_tag php.ini setting]

Echo and print: In PHP there are two basic ways to get output: echo and print. echo and print are more or less the same. They are both used to output data to the screen. echo and print is not actually a function (it is a language construct), echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.

<?php
	echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>  
<?php
	print "I'm about to learn PHP!";
?>  

1. History Of PHP , What is PHP , What is Web server

PHP as it’s known today is actually the successor to a product named  PHP/FI. Created in 1994 by Rasmus Lerdorf, Originally used for tracking visits to his online resume.

PHP is a server­side scripting Programming language. This language uses for dynamic website and dynamic web Application. Alternative to php (Perl, ASP.Net, Python, Ruby, JAVA)

Web server is an information technology processes requests via  HTTP, the basic network protocol used to distribute information on the World Wide Web

Some of web Server Name: [ Appache , .net , Tomcat ,  nginx]