<?php
if(stristr($_SERVER['HTTP_USER_AGENT'], "Mobile")){ // if mobile browser
?>
<link rel="stylesheet" href="style-400.css" type="text/css" />
<?php
} else { // desktop browser
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<?php
}
?>
border-spacing
propertytable {
border-collapse:separate;
border-spacing:0 15px;
}
Another way is to put additional separator TRs <tr class="separator" />
between rows.separator {
height: 10px;
}
Third way is to use margin-bottom
propertytr {
display: block;
margin-bottom: 15px;
}
--patch
or -p
is usedgit add --patch
Similar to the above commandgit add -p
Possible answers for the command:
y
stage this hunk for the next commit
n
do not stage this hunk for the next commit
q
quit; do not stage this hunk or any of the remaining hunks
a
stage this hunk and all later hunks in the file
d
do not stage this hunk or any of the later hunks in the file
...
The complete list of the possible answers is on the link of the note.txt
extension to .php
ren *.txt *.php
document.addEventListener("scroll", setBG);
function setBG() {
if (!bgSet) {
var bgSet=1;
id('table_footer').style.background='url(/images/footer.jpg?tg)';
document.removeEventListener("scroll", setBG);
console.log('fired');
}
}
$d = date("D");
if($d == "Fri"){
echo "Have a nice weekend!";
} elseif($d == "Sun"){
echo "Have a nice Sunday!";
} else{
echo "Have a nice day!";
}
echo "\n";
Outputs Have a good morning!
if the current time is less than 10, and Have a good day!
if the current time is less than 20. Otherwise it will output Have a good night!
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
Prints Adult
If $age
is more than 18
, and Teenager
if the variable is less than 12. Otherwise it prints Child
$age = 20;
if ($age > 18) {
echo 'Adult';
} else if ($age > 12) {
echo 'Teenager';
} else {
echo 'Child';
}
$d = date("D");
if ($d == "Fri"){
echo "Have a nice weekend!";
}
If the current hour is less than 20, the code will output "Have a good day!"
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
}
If $age
is more than 18
, prints Adult
$age = 20;
if ($age > 18) {
echo 'Adult';
}
$colors = ["Red", "Green", "Blue"];
$colors[] = "Yellow";
Associative arrays
$student = [
"name"=>"George",
"weight"=>77,
"height"=>1.8,
"male"=>true
];
$student["male"] = true;
echo 'George is ' . $student['weight'] . 'kg'."\n";
Multidimensional arrays
$students = [
"George"=> [
"name"=>"George",
"weight"=>77,
"height"=>1.8,
"male"=>true
],
"Alex"=> [
"name"=>"Alex",
"weight"=>87,
"height"=>2.8,
"male"=>true,
"parents"=> [
"father"=>"David",
"mother"=>"Marta",
]
],
];
echo 'Alex weighs ' . $students['Alex']['weight'] . 'kg'."\n";
echo "Alex's father is: " . $students['Alex']['parents']['father'];
printMe()
is defined after it's called but it works without errorsecho printMe();
function printMe() {
return 'Print some text';
}
Exception is conditional function
.
In this example function foo()
will not be defined until the if ($makefoo)
conditional statement gets executed$makefoo = true;
/* We can't call foo() from here
since it doesn't exist yet,
but we can call bar() */
// foo();
bar();
if ($makefoo) {
function foo()
{
echo "I don't exist until program execution reaches me.\n";
}
}
/* Now we can safely call foo()
since $makefoo evaluated to true */
if ($makefoo) foo();
function bar()
{
echo "I exist immediately upon program start.\n";
}
Functions within functions.
Function bar()
will not be defined until the function foo()
is executedfunction foo()
{
function bar()
{
echo "I don't exist until foo() is called.\n";
}
}
/* We can't call bar() yet
since it doesn't exist. */
// bar();
foo();
/* Now we can call bar(),
foo()'s processing has
made it accessible. */
bar();
Note: All functions in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa