Basically, PHP is interpreted but PHP is compiled down to an intermediate byte-code that is then interpreted by the runtime Zend engine.
● Convert the code to a bytecode that can be used by the runtime engine.
● Resolve functions,names and classes names.
● Creating a symbol table
● Goes through the bytecode line by line and executes it
● Handling Exception
The answer to this is both yes and no. Variables and their declaration in PHP are completely case sensitive while function names are not.
In static websites, content can't be changed after running the script. You can't change anything on the site. It is predefined.
In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visit or reload. Google, yahoo and every search engine is the example of dynamic website.
PHP4 doesn't support oops concept and uses Zend Engine 1. PHP5 supports oops concept and uses Zend Engine 2.
Some popular PHP frameworks are:
- CodeIgniter
- CakePHP
- Symfony
- Zend Framework
- Yii 2
Scalar type declarations Return type declarations Null coalescing operator (??) Spaceship operator Constant arrays using define() Anonymous classes Closure::call method Group use declaration Generator return expressions Generator delegation Space ship operator
Echo can output one or more string but print can only output one string and always returns 1. Echo is faster than print because it does not return any value.
IN PHP variable cannot be start with numeric like “$3abc”:.It will throw an error
● IN PHP variable can not be like “$a bc=20;”
● PHP Parse error: syntax error, unexpected 'bc' (T_STRING)
$----- is variable that store the value
$$ — is a reference variable that stores the value of the variable.
PHP constants are name or identifier that can't be changed during execution of the script. PHP constants are defined in two ways: Using define() function Using const() function constant is a container whose value cannot be changed during the execution of the program. define(‘NAME’,’Asha’); echo NAME;
PHP data types are used to hold different types of data or values. There are 8 primitive data types which are further categorized in 3 types: Scalar types Compound types Special types
- String
- Integer
- Float (floating point numbers - also called double)
- Boolean
- Array
- Object
- NULL
- Resource
== : It returns true if the value gets matched. === (Identical Operator): It return true if value and data type both matched
The isset() function checks if the variable is defined and not null.
It is composed of three expressions , one is condition and two operators which describe what instruction to be performed when the specified condition is true or false.
There are three data types in php 1. Predefined Data type. - int, bool, string,float etc 2. User defined Data type - array , object 3. Special data type. - NULL , resource
Array is a user defined data type used to store the value of one or more values of similar or different data types in a single variable.
There are three types of array in php
1. Index array or numeric array - Array with numeric key
2. Associative array - Array with string key
3. Multi-dimensional array - Array containing one or more array
● in_array : = it check value exists in an array or not Syntax: in_array(“searchtext”,array);
● array_key_exists : check specified key exists in array or not. Syntax: array_key_exists(“searchkey”,array);
● array_key : return array containing the key.
Example:1 $a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlande r");
print_r(array_keys($a,"Highlander"));
OUTPUT: Array ( [0] => Volvo [1] => BMW [2] => Toyota )
Example:2 $a=array("Volvo"=-->"XC90","BMW"=>"X5","Toyota"=>"Highlande r");
print_r(array_keys($a,"Highlander"));
OUTPUT: Array ( [0] => Volvo [1] => BMW [2] => Toyota )
● array_map : sends each value of an array to a user-made function, and returns an array with new values, given by the user-made function.
Example 1 :
function myfunction($v){
return($v*$v);
}
$a=array(1,2,3,4,5);
print_r(array_map("myfunction",$a));
OUTPUT: Array ( [0] => 1 [1] => 4 [2] => 9 [3] => 16 [4] => 25 )
● array_diff : Compare the values of two arrays, and return the differences.It return all the values from one array that are not present in any other array.
Example:1 $a1=array("a"=-->"red","b"=>"green","c"=>"blue","d"=>"yello w");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_diff($a1,$a2);
print_r($result);
OUTPUT: Array ( [d] => yellow )
● array_intersect :Compare the values of two arrays, and return the matches.It returns all the values from the first array which is present in all other arrays.
Example:1 $a1=array("a"=-->"red","b"=>"green","c"=>"blue","d"=>"yello w");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_intersect($a1,$a2);
print_r($result);
OUTPUT: Array ( [a] => red [b] => green [c] => blue )
● array_push :Insert one more element into end of the array
● array_pull :remove one or more element from the end of the array
● array_shift :remove first element from the array
● array_unshift :add one or more element to the beginning of the array
● array_unique :remove duplicate values from an array
● array_count_values :count no. of times value repeated in an array
Example:1 $a1=array(bye,bye,hello);
$result=array_count_values($a1);
print_r($result);
OUTPUT: Array ( [bye] => 2 [hello] => 1 )
● count/size_of :count the no. of elements present in an array
● shuffle: used to randomize the order of an element in an array.
● rand: used to generate the random integer.
● array_rand : used to get one or more random values from an array.
● gettype(): used to get the type of a variable.
There are many array functions in PHP:
strtolower()
strtoupper()
ucfirst()
lcfirst()
ucwords()
strrev()
strlen()
array_combine: used to combine two or more arrays in a key value pair.One array is used as key and other array is used as value.
array_merge: used to combine two or more arrays and create a new array.It merges one or more arrays in such a way that the value of another array appends at the end of the first array.
Differences are:
● explode : convert string into an array
Example1 :
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
OUTPUT: Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )
● Implode : convert array int an string
Example:1 $arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr)."";
OUTPUT: Hello World! Beautiful Day!
● extract :This function uses array keys as variable names and values as variable values
Example:1 $a = "Original"; $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
OUTPUT: $a = Cat; $b = Dog; $c = Horse
There are three main error types in PHP:
1. Notices. These are non-critical errors that can occur during the script execution. These are not visible to users. Accessing an undefined variable is an example of a 'Notice'.
2. Warnings. These are more critical than Notices, but just like them, Warnings don't interrupt the script execution. However, these are visible to the user by default. Example: include() a file that doesn't exist.
3. Fatal. This is the most critical error type which, when occurs, immediately terminates the script execution. Accessing a property of a non-existent object or require() a non-existent file is an example of this error type
- Private – Detectable only in its own class
- Public – Can be seen by any other code accessing the class
- Protected – Can be seen by classes parent(s) and classes that extend the current class
Rasmus Lerdorf who created the language in 1994.
WordPress
Joomla
Magento
Drupal
NULL is a particular type of value in PHP. It represents a variable with no value and is usually used to denote the absence of a deal.
The GET and POST methods are two distinct ways of sending information to the server. The GET method is used when requesting data, while the POST method is used to submit data such as form information.
GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.POST method variables are not displayed in the URL.
Interface contains no data variables rather than function prototypes. It is defined by using the “interface” keyword. The “implements” operator is used to extend the interface. You can inherit all the interface classes at the time of extension. All the interfaces are separated by a (,) comma. All the methods must be implemented within a child class. The class implements an interface that uses the same method signatures as defined in an interface.
Inheritance is a concept whereby one class assigns the formation and behavior defined in another class. If the inheritance applies to one class, this is referred to as single inheritance; if it depends on several classes, this is referred to as multiple inheritance.
-
To Share this Link, Choose your plateform
1. What is PHP?
PHP stands for Hypertext Preprocessor. It is an open source server-side scripting language which is widely used for web development. It supports many databases like MySQL, Oracle, Sybase, Solid, PostgreSQL, generic ODBC etc.