×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
gmail account.
Using IF statement:SELECT *
FROM `students`
WHERE IF(LENGTH(mail), mail, mail2) LIKE '%gmail.com%'
ORDER BY points
Using OR logical operator:SELECT *
FROM `students`
WHERE
(`mail` LIKE '%gmail.com%' AND LENGTH(mail))
OR
(mail2 LIKE '%gmail.com%')
ORDER BY points
Using CASE SELECT *
FROM `students`
WHERE
(CASE
WHEN LENGTH(mail) THEN mail
ELSE mail2
END) LIKE '%gmail.com%'
ORDER BY pointsinstall command reads the composer.json file from the current directory, resolves the dependencies, and installs them into vendor composer install / composer i
If composer.lock file exists, installs exactly what's specified in this file
Otherwise
1. Reads composer.json file to look out what dependencies needs to be installed
2. Writes the composer.lock with the information of the project (installed dependencies)major version will stick to 1 but minor and patch will be the latest versions"dependencies": {
"moment": "^1.6.2"
}
Only updates patch but major and minor will be the specified versions"dependencies": {
"moment": "~1.6.2"
}
Exactly the specified version 1.6.2 will be installed"dependencies": {
"moment": "1.6.2"
}
The latest version of the package will be installed"dependencies": {
"moment": "*"
}childNodes returns an array of an element's child nodes.
JSfunction setText() {
let a = document.getElementById("demo");
let arr = a.childNodes;
for(let x=0;x<arr.length;x++) {
arr[x].innerHTML = "new text";
}
}
//calling the function with setTimeout to make sure the HTML is loaded
setTimeout(setText, 500);
HTML of the example<div id ="demo">
<p>some text</p>
<p>some other text</p>
</div>
Note: The code above changes the text of both paragraphs to new text//calling the function in window.onload to make sure the HTML is loaded
window.onload = function() {
//creating a new paragraph
var p = document.createElement("p");
p.innerHTML = 'Some new text 1';
//adding the paragraph to the div
var div = document.getElementById("demo");
div.appendChild(p);
};
HTML<div id="demo">some content</div>getElementsByTagName method returns all of the elements of the specified tag name as an array.
The following example gets all paragraph elements of the page and changes their content.
JSlet arr = document.getElementsByTagName("p");
for (let x = 0; x < arr.length; x++) {
arr[x].innerHTML = "Hi there";
}
HTML of the example<p>Hi</p>
<p>Hey</p>
<p>Hello</p>
<div>Hello there</div>
Note: We used the length property of the array to loop through all the selected elements in the above exampledatetime objects using createFromFormat static method of DateTime built-in class$first_date = DateTime::createFromFormat('Y-m-d', "2020-12-23");
$second_date = DateTime::createFromFormat('Y-m-d', "2020-12-30");
Using diff() method of DateTime class we actually calculate differences between the two dates and we get the result in days$difference_between_the_days = $second_date->diff($first_date)->format("%a");
echo $difference_between_the_days;class Foo
{
public static $staticVariable = 'foo';
public static function getVariableStatic() {
return self::$staticVariable;
}
public function getVariableNONStatic() {
return self::$staticVariable;
}
}
We can not access $staticVariable using an object directly:$foo = new Foo();
print $foo->staticVariable;This will produce the following error message:Notice: Accessing static property Foo::$staticVariable as non static...
But there are several ways to access static variable using an object:
1. Using static getter method:$foo = new Foo();
print $foo->getVariableStatic();
2. Using non-static getter method:$foo = new Foo();
print $foo->getVariableNONStatic();
php.net: A property declared as static cannot be accessed with an instantiated class object (though a static method can).class BLock { }
class Lock {
private $isLocked;
public function __construct() {
}
public function lock() {
$this->isLocked = true;
}
public function unLock() {
$this->isLocked = false;
}
public function isLocked() {
return $this->isLocked;
}
}
class Chest {
private $lock;
public function __construct(Lock $lock) {
$this->lock = $lock;
}
public function close() {
$this->lock->lock();
echo 'Closed' . PHP_EOL;
}
public function open() {
if ($this->lock->isLocked()) {
$this->lock->unLock();
}
echo 'Opened' . PHP_EOL;
}
public function isClosed() {
return $this->lock->isLocked();
}
}
$chest = new Chest(new Lock);
// $chest = new Chest(new Block);
$chest->open();
$chest->close();In this example Chest class constructor waits to receive Lock class object.
If we pass any other class object, we will get an error like the following:
Fatal error: Uncaught TypeError: Argument 1 passed to Chest::__construct() must be an instance of Lock, instance of BLock givenclass - blueprint, skeleton, basic structure of an object
property - data of an object, equivalent to PHP variables
method - behavior of an object, equivalent to PHP functions
inheritance - ability to use properties and methods of an existing class
polymorphism - ability to have many forms, when a class has varying functionality while sharing a common interfaces
encapsulation - to hide or protect certain properties or methods of an object
abstraction - a concept in which a class has methods without implementation