<?php
$a=3;
$b=$a++;
$c= ++$b;
echo $a."--".$b."--".$c; //output: 4--4--4
?>
----------------------------------------
<?php
$a="10 ear";
$b="11 ear";
$c= $a+$b;
echo $c; //output: 21
echo "10 ear" + "10 ear"; //output: 20
echo "10 ear" + "ear 10"; //output: 10
echo "ear 10" + "10 ear"; //output: 10
echo "ear 10" + "ear 10"; //output: 0
?>
--------------------------------
<?php
// cann't be declared a variable type numeric e.g. $2, $4 etc.
$2="ggggg";
echo $2; // Parse error: parse error, expecting `T_VARIABLE' or `'$'' in C:\xampp\htdocs\dilip\pending\doubts.php on line 3
?>
------------------------------
// Get Browser
<?php
function getBrowser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/windows|win32/i', $u_agent)) {
$platform = 'windows';
}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$bname = 'Mozilla Firefox';
$ub = "Firefox";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$bname = 'Google Chrome';
$ub = "Chrome";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$bname = 'Opera';
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$bname = 'Netscape';
$ub = "Netscape";
}
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
$version= $matches['version'][0];
}
else {
$version= $matches['version'][1];
}
}
else {
$version= $matches['version'][0];
}
// check if we have a number
if ($version==null || $version=="") {$version="?";}
return array(
'userAgent' => $u_agent,
'name' => $bname,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern
);
}
---------------------------------------
<?php
$a=80;
function abc()
{
global $a;
$b=$a;
echo $b; //output : 80 if $a is defined "global $a" under abc() function
}
abc();
?>
------------------------------------
<?php
$d1=mktime(2,0,0,10,21,2010); // mktime(hour,minute,second,month,day,year);
$d2=mktime(0,0,0,12,21,2010);
echo "Hours difference = ".floor(($d2-$d1)/3600) . "<br>";
echo "Minutes difference = ".floor(($d2-$d1)/60) . "<br>";
echo "Seconds difference = " .($d2-$d1). "<br>";
echo "Month difference = ".floor(($d2-$d1)/2628000) . "<br>";
echo "Days difference = ".floor(($d2-$d1)/86400) . "<br>";
echo "Year difference = ".floor(($d2-$d1)/31536000) . "<br><pre>";
?>
output:
Hours difference = 1462
Minutes difference = 87720
Seconds difference = 5263200
Month difference = 2
Days difference = 60
Year difference = 0
---------------------------------
<?php
// array_unique — Removes duplicate values from an array
$input = array(4, "4",3, "3");
$result = array_unique($input);
print_r($result); // [0] => 4 [2] => 3
?>
<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result); // [a] => green [0] => red [1] => blue
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
?>
<hr>
<?php
// merge 2 array
// Remove duplicate value from the array
$arr1=array(1,2,3,4,5);
$arr2=array(4,5,6,6);
$arr3=array_merge($arr1,$arr2);
print_r($arr3); // [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 4 [6] => 5 [7] => 6 [8] => 6
$uniq=array_unique($arr3);
print_r($uniq); // [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [7] => 6
?>
--------------------------