SELECT SUM(avg1) FROM (SELECT user_id, AVG(score) as avg1 FROM results GROUP BY user_id)
in this case results table might have multiple records on 1 user id
so basically it gets average score of all users and than sums all average number$arr = ['key0' => 'val0','key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'];
$removeKeys = ['key1', 'key2', 'key3'];
$arr = array_diff_key($arr, array_flip($removeKeys));
Async/Await
was created to simplify the process of working with and writing chained promises. Async
functions return a Promise. If the function throws an error, the Promise will be rejected. If the function returns a value, the Promise will be resolved.$
followed by curly brackets ${expression}
let name = 'George'
let age = 25
document.write(`My name is ${name} and I am ${age} years old!`)
hoisted(); // logs "foo"
function hoisted() {
console.log('foo');
}
Function expressions - anonymous functions are not hoisted:notHoisted(); // TypeError: notHoisted is not a function
var notHoisted = function() {
console.log('bar');
};
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 versais_optional
column comment which exists in decorations
table using information_schema
databaseSELECT COLUMN_COMMENT
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'geiger'
AND TABLE_NAME = 'decorations'
AND COLUMN_NAME = 'is_optional'