×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
p
element will be all uppercase and underlinedp {
text-decoration: underline;
text-transform: uppercase;
}
class A {
final public static function who() {
echo __CLASS__;
}
}
class B extends A {
public static function who() {
echo __CLASS__;
}
}
B::who();
Fatal error: Cannot override final method A::who()
div.sticky {
background-color: yellow;
position: sticky;
top: 0;
}
A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place like position:fixed
p
elements that have div
element as a parent of any leveldiv p {
color: red;
}
Selects all the p
elements that are children of the element with id #id1
#id1 p {
color: green;
}
Selects all p
elements that have parent element with class .class1
.class1 p {
color: yellow;
}
replaceChild
(newNode, oldNode) method is used.
JSwindow.onload = function() {
let p = document.createElement("p");
p.innerHTML = "This is new";
// Replaces the first p with the new one
let parent = document.getElementById("demo");
parent.replaceChild(p, document.getElementById("p1"));
};
HTML<div id="demo">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
Note: The code above creates a new paragraph element that replaces the existing p1
paragraphremoveChild
(node) method
JSwindow.onload = function() {
var parent = document.getElementById("demo");
parent.removeChild(document.getElementById("p1"));
};
HTML<div id="demo">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
insertBefore
(node1, node2) inserts node1
as a child before node2
JSfunction myFunction() {
// Creates new list item
let newItem = document.createElement("li");
newItem.innerHTML = "Water";
// Puts list item into myList before "tea" item
let list = document.getElementById("myList");
list.insertBefore(newItem, document.getElementById("tea"));
}
HTML<ul id="myList">
<li>Coffee</li>
<li id="tea">Tea</li>
<li>Cocacola</li>
</ul>
<p>Click the button to insert an item to the list.</p>
<button onclick="myFunction()">Try it</button>
quotation marks
, then the parameter is going to be interpreted as a column value.
Converts a string or column value to UPPER-CASE
SELECT
UPPER(first_name),
UPPER('Converts a string or column value to UPPER-CASE')
FROM students
Converts a string or column value to lower-case
SELECT
LOWER(first_name),
LOWER('Converts a string or column value to lower-case')
FROM students
Joins strings and columns togetherSELECT
CONCAT(first_name, ' ', 'joins', ' ', 'strings', ' ', 'and', ' ', 'columns')
FROM students
The function LENGTH
Returns the length (in bytes) SELECT
id,
first_name,
LENGTH(first_name) first_name_length
FROM students
Note: Each Georgian letter takes three bytes
The function is similar to CONCAT
where WS
means - With Separator.
The first parameter is the separator between each one of the additional fields, that we pass as next parametersSELECT
CONCAT_WS(' - ', first_name, 'joins', 'strings', 'and', 'columns', 'with', 'separator')
FROM students
The function TRIM
removes leading and trailing spacesSELECT
LENGTH(' text ') length,
LENGTH(TRIM(' text ')) length_with_trim
The function RTRIM
removes trailing spaces (removes spaces from the end)SELECT
LENGTH(' text ') length,
LENGTH(RTRIM(' text ')) length_with_right_trim
The function LTRIM
remove leading spaces (removes spaces from the beginning)SELECT
LENGTH(' text ') length,
LENGTH(LTRIM(' text ')) length_with_left_trim
The function LEFT
returns leftmost characters. In this case 5 characters because we pass 5 as second parameterSELECT
LEFT(first_name, 5) AS 'five leftmost characters'
FROM students
The function RPAD
appends string (third parameter) the specified number of times (second parameter) to the first parameter.
In this example each one of the student's last name that is less than 10 characters long, is filled with -
SELECT
RPAD(first_name, 10, '-') AS 'student name'
FROM students
Complete list of string functions on the official documentation: https://dev.mysql.com/doc/refman/8.0/en/string-functions.htmlAnimal
abstract class and both implement the same method prey()
differentlyabstract class Animal {
// child classes must implement this
abstract function prey();
public function run() {
echo "I am running!\n";
}
}
class Dog extends Animal {
public function prey() {
echo "I killed the cat !\n";
}
}
class Cat extends Animal {
public function prey() {
echo "I killed the rat !\n";
}
}
$dog = new Dog();
$cat = new Cat();
$dog->prey(); // I killed the cat !
$cat->prey(); // I killed the rat !
$dog->run(); // I am running!
$cat->run(); // I am running!
parent
keywordparent::__construct($name);
Complete example:class User {
public $username;
function __construct($name) {
$this->username = $name;
}
}
class Admin extends User{
public $admin_level;
function __construct($name, $admin_level) {
parent::__construct($name);
$this->admin_level = $admin_level;
}
}
$admin1 = new Admin('Tom', 'Manager');
echo $admin1->username;
echo "\n";
echo $admin1->admin_level;
If there is no constructor in child class, then parent class constructor will be called (when appropriate parameters are passed)