×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
$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'];
min()
finds the lowest value from its arguments
echo min(10, 15, 7, 9, 17)."\n"; // 7
Function max()
finds the highest value from its arguments
echo max(10, 15, 7, 9, 17)."\n"; // 17
Function count()
counts all elements in the array
echo count([10, 15, 7, 9, 17])."\n";
Function round()
rounds a floating-point number to its nearest integer
echo(round(0.75))."\n"; // returns 1
echo(round(0.5))."\n"; // returns 1
echo(round(0.49))."\n"; // returns 0
Function floor()
rounds the floating-point number down
echo floor(3.3)."\n";// 3
echo floor(7.84)."\n";// 7
echo floor(-4.8)."\n";// -5
Function ceil()
rounds the floating-point number up
echo ceil(3.3)."\n";// 4
echo ceil(7.84)."\n";// 8
echo ceil(-4.8)."\n";// -4
Function rand()
generates a random number
echo rand()."\n";
// Generates a random number from the range
echo rand(10, 100)."\n";
Function sqrt()
returns the square root of a number
echo sqrt(64)."\n"; // 8
Function pow()
raises 2 to the power of 3
echo pow(2, 3)."\n"; // 8
Function pi()
Returns PI value
echo pi()."\n";// 3.1415926535898
Function abs()
returns the positive (absolute) value of a number
echo abs(-12)."\n";
Function decbin()
converts decimal number into binary
echo decbin(2)."\n";// 10
echo
can take multiple parameters
echo 'one', 'two', 'three', "\n";
2. print
statement returns 1
$print_returns = print('some text')."\n";
echo "print_returns Value: $print_returns" . "\n";
echo
prints 1 after print
statement is executed
echo print "123", "\n";
3. echo
is a little bit faster than print
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');
}
}
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;
}
<?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
}
?>
public function getCategoryTreeJSON()
{
$query = " SELECT
c1.id,
c1.name,
c1.parent_id,
(
SELECT
COUNT(c2.id)
FROM
categories AS c2
WHERE
c2.parent_id = c1.id
)
AS children_count
FROM
categories AS c1";
$categoryDetails = json_decode(json_encode(DB::select($query)), true);
$array_tree = $this->getCategoryTreeArray($categoryDetails);
return json_encode($array_tree);
}
Recursive function that returns multi level associative array.
Base case: when children_count
is equal to zero.public function getCategoryTreeArray($items, $parent_id = 0)
{
$branch = [];
$array_JSON = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parent_id) {
if ($item['children_count'] > 0) {
$array_JSON[] = [
'id'=>$item['id'],
'title'=>$item['name'],
'subs'=>$this->getCategoryTreeArray($items, $item['id'])
];
} else {
$array_JSON[] = [
'id'=>$item['id'],
'title'=>$item['name']
];
}
}
}
return $array_JSON;
}
multiple
attribute and append []
to input name<input type="file" multiple="multiple" name="files[]" placeholder="Attach file"/>
To validate show errors on client side we have to append input name with .*
Complete example of the form-group
<div class="form-group">
<label for="files">Attach File</label>
<i id="add_new_file" class="ki ki-plus text-success pointer" title="Add New File"></i>
<input type="file" class="form-control mb-2 {{ $errors->has('files.*') ? 'is-invalid' : '' }}" multiple="multiple" name="files[]" placeholder="Attach file"/>
@if($errors->has('files.*'))
<div class="invalid-feedback">
<strong>{{ $errors->first('files.*') }}</strong>
</div>
@endif
</div>
Server side validation of mime typespublic function rules()
{
return [
'comment' => 'sometimes|nullable|min:2|max:255',
'files.*' => 'sometimes|nullable|mimes:pdf,docx,xlsx,pptx,rar,zip,png,jpg',
];
}
It's necessary the validator key files
to be appended with the same symbols .*