$array = [1, 2, "name"=>"Three", 4];
print_r($array);
ResultArray
(
[0] => 1
[1] => 2
[name] => Three
[2] => 4
)
If we set higher index manually, it will continue adding 1 to the max index$array = [1, 2, 7=>"Three", 4];
print_r($array);
ResultArray
(
[0] => 1
[1] => 2
[7] => Three
[8] => 4
)
If we set higher index manually, it will continue adding 1 to the index$array = [1, 2, 7=>"Three", 4=>"forth", 25];
print_r($array);
ResultArray
(
[0] => 1
[1] => 2
[7] => Three
[4] => forth
[8] => 25
)
Only integer and string values are allowed as array keys
$array = [
1 => "a",
"1" => "b",
"-1" => "-b",
'1.5' => "c",
true => "d",
];
print_r($array);
ResultArray
(
[1] => d
[-1] => -b
[1.5] => c
)
`
$items = array("me", "you", "he");
array_push($items, "she", "we");
print_r($items);
``
Formats can be:
echo "Today is ". date("Y/m/d") . "\n";
echo "Today is ". date("d/m/Y"). "\n";
echo "Today is ". date("D/M/Y"). "\n";
echo "Today is ". date("d/M/Y"). "\n";
echo "Today is ". date("d.m.Y"). "\n";
echo "Today is ". date("d-m-Y"). "\n";
echo "Today is ". date("l"). "\n";
`
`
Output:
Today is 2022/10/22
Today is 22/10/2022
Today is Sat/Oct/2022
Today is 22/Oct/2022
Today is 22.10.2022
Today is 22-10-2022
Today is Saturday
`<?php
$x = 10;
// Sum of numbers from 1 to n
$sum = 0;
for ($i = 1; $i <= $x; $i++) {
$sum += $i;
}
echo "SUM of numbers from 1 to $x: $sum\n";
// easy way to calculate SUM of numbers to n
$sum = $from1To * ($x+1) / 2;
echo "SUM of numbers from 1 to $x: $sum\n";
function str_info($string,$pos){
$arr= ["length is: ". strlen($string),
"UPPER:". strtoupper($string),
"string possitin: " .strpos($string, $pos),
"reverse is: ".strrev($string)];
return implode("\n", $arr) ; // აქ შეაერთებს მასივის ელემენტებს და დააბრუნებს ტექსტის სახით
შედეგი
length is: 13
UPPER:YOU ARE GREAT
string possitin: 4
reverse is: taerg era uoY