Introduction

* PHP stands for PHP: Hypertext Preprocessor .
* This is a widely-used scripting language that is especially suited for Web development .
* The main goal of the language is to allow web developers to create dynamically generated webpages .

Why php ?

* PHP is an open source software.It is free to download and use.
* Platform independent (windows , linux etc .)
* Easy to learn .
* Supports wide range of databases(Mysql,Oracle etc.) .


Creating a simple PHP Program

* It starts with <?php and ends with ?> tag.
* For Output , it use echo,print,print_r.
* Language Construct : Language constructs are something which executes directly without being parsed. This is like reserved keyword which dealt directly with parser. The key difference between functions and language constructs is the parser deals directly with language constructs and functions are mapped and simplified to a set of language constructs before parsing. So these may or may not require parentheses and the reason some have return values while others don't depends entirely on the specific technical details of the PHP parser implementation. echo and print are language construct, but print_r() is a predefined function.

example:
  	
<?php
$v = "hello world"; // variable in php represented by a dollar sign
echo $v;  
?>
		
Output :
hello world

Echo(Output one or more strings) :

It is not actually a function (it is a language construct) so you are not required to use parentheses with it .

example:
  
<?php	
$state = 'orissa'; 
$cap = 'bbsr'; 
echo 'cap is $cap';
?>
		

Print(Output a string) :

Syntax Print (string arg);

Note :print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.
example:
  
<?php	
$i=print('Hello World'); 
print $i; 
print '\n print() also works without \n parentheses.';
?>
		

Print_r(Output a string) :

It is used to return/print an array in a human readable form.
Syntax print_r ( mixed expression [, bool return]);

Note :print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.
example:
 
<?php 	
$arr=array(array('name'=>'Debendra','batch'=>'5','designation'=>'programmer'),
		   array('name'=>'Arun','batch'=>'5','designation'=>'programmer'),
		   array ('name'=>'Satya','batch'=>'5','designation'=>'Tester'),
		   array('name'=>'Rama','batch'=>'2','designation'=>'programmer')); 
print_r($arr);
?>
		
Output :
Array ([0] => Array ([name] => Debendra[batch] => 5[designation] => programmer) [1] => Array ( [name] => Arun [batch] => 5 [designation] => programmer ) [2] => Array ( [name] => Satya [batch] => 5 [designation] => Tester ) [3] => Array ( [name] => Rama [batch] => 2 [designation] => programmer ) )

Difference between echo and print :

echo:
     1. echo can take more than one parameter when used without parentheses. The syntax is echo expression [, expression[, expression] ... ]. Note that echo ($arg1,$arg2) is invalid.
     2. echo does not return any value
     3. Syntax - echo hello , world
     4. In PHP, echo is not a function but a language construct.
Print:
     1. print only takes one parameter.
     2. print always returns 1 (integer).
     3. Syntax - print (string $arg)
     4. In PHP, print is not a really function but a language construct. However, it behaves like a function i.e. it returns a value.

Var_dump :

* It dumps/gives all the detail information about a variable.
* The var_dump function displays structured information about expressions that includes its type and value. Arrays are explored recursively with values indented to show structure.
Syntax void var_dump(mixed $expression[,mixed $expression[,$... ]])
example:
 
<?php  	
 $arr = Array('name'=>'Afixi Technologies Pvt Ltd','type'=>'software','total_emp'=>'50'); 
	var_dump($arr);
?>		
		
Output :
array(3) { ['name']=> string(26) 'Afixi Technologies Pvt Ltd' ['type']=> string(8) 'software' ['total_emp']=> int(50) }

Phpinfo(Outputs PHP information) :

* Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.

Syntax Print phpinfo();

Note :Difference between " " (double quote) & '' (single quote)
" " can pasre . '' is used as literal.
example:
 
<?php  	 	
$country='India';
print "$country";//India 
print '$country';//$country 
?>
		

Questions

  1. What is the difference between echo , print , print_r ?
  2. What is difference between var_dump and print_r ?
  3. What is the use of var_dump() ?
  4. How can we define array ?
  5. Write code for display as: <php echo "Afixian's"; ?> ?
After editing Click here:
Output:
Hello World