PHP Array inicializace PHP
$country[0] = "cz"
$country[1] = "sk"
$country[2] = "de"
$country[3] = "uk"
$country[4] = "fr"
// this do same
$country[] = "cz"
$country[] = "sk"
$country[] = "de"
$country[] = "uk"
$country[] = "fr"
// or
$country = array('cz','sk','de','uk','fr');
// get array items count
$length = count($country);
for($i=0;$i<$length;$i++){
print $country[$i].'<br>';// cz sk de uk fr
}
// or like this
$country[50] = 'ca';
$country[10] = 'fr';
$country[20] = 'us'
// now country will index 51
$country[] = 'ru';
// or
$country = array('5'=>'cz','sk','de','uk','fr');
/*
Array
(
[5] => cz
[6] => sk
[7] => de
[8] => uk
[9] => fr
)
*/
// you can do this
$country["cz"] = 1571;
$country["sk"] = 1572;
$country["de"] = 1573;
$country["uk"] = 1574;
$country["fr"] = 1575;
print $country["uk"]; // 1574
// print all items key and value
foreach ($country as $key => $value){
print $key; // cz, sk, de, uk, fr
print $value; // 1571, 1572, 1573, 1574, 1575
}
77LW NO topic_id
AD
Další témata ....(Topics)
Nejdůležitější informace, které získáme z cesty souboru.
// soubor, který je volán jako první
print $_SERVER ['SCRIPT_FILENAME']; // /www/domain/subdomain/cesky-jazyk/gramatika/index.php
$path_parts = pathinfo($_SERVER ['SCRIPT_FILENAME']);
echo $path_parts['dirname']. " dir"; // /www/domain/subdomain/cesky-jazyk/gramatika
echo $path_parts['basename']. " base"; // index.php
echo $path_parts['extension']. " ext"; // php
echo $path_parts['filename']. " file"; // index az od PHP 5.2.0
// cesta k souboru, ve kterém je aktualni print a byl inkludován - include v index.php
print __FILE__; // /www/subdomains/cesk-jazyk/templates/header.php
Textarea selection - získání pozice karety kurzoru.
// FOR Gecko Browser selectionStart / selectionEnd selection length
function getPos(){
if (typeof document.getElementById('idTextarea').selectionStart != 'undefined') {
var nPosCursor = document.getElementById('idTextarea').selectionStart;
var nEndPos = document.getElementById('idTextarea').selectionEnd;
return nPosCursor;
}
return 0; // or -1
}
// source by javascript-array.com/guides/javascript_faq/
//Internet Explorer 4+, Mozilla/Gecko/Firefox
function getCaretPos(obj)
{
obj.focus();
if(obj.selectionStart) return obj.selectionStart; //Gecko
else if (document.selection) //Internet Explorer
{
var sel = document.selection.createRange();
var clone = sel.duplicate();
sel.collapse(true);
clone.moveToElementText(obj);
clone.setEndPoint('EndToEnd', sel);
return clone.text.length;
}
return 0;
}
List of usefull JavaSript functions and constans
var 1_radian_to_degree = 180 / Math.PI; // 57,295779513082320876798154814105 degree
var 1_degree_to_radian = Math.PI / 180; // 0,01745329251994329576923690768489 radian
var 360_degree = 2 * Math.PI * 1_radian_to_degree;
parseInt("10.33") // returns 10 string to integer
parseFloat("10.33") // returns 10.33 string to float
// change sign
var a = -1;
a = a * -1; // +1
// random sign
a *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
var who_is = 58;
var type = (typeof who_is); // number
Math.E // natural logarithms, e, approximately 2.718281828459045
Math.LN10 // natural logarithm of 10, approximately 2.302585092994046
Math.LN2 // natural logarithm of 2, approximately 0.6931471805599453
Math.PI // approximately 3.141592653589793
Math.SQRT1_2 // square root of 1/2 which is approximately 0.7071067811865476
Math.SQRT2 // square root of 2, approximately 1.4142135623730951
Math.pow(4, 2) = 16 // 4 x 4 ... base 4 to the exponent 2 power
Math.abs(-5) absolute value of a number // return 5
Math.tan(degrees * Math.PI / 180) // get tangent from degrees
Math.tan(degree * Math.PI / 180)*adjacent = opposite
opposite / Math.tan(degree * Math.PI / 180) = adjacent
Math.acos(adjacent / hypotenuse) // angle of a right-angle triangle in radians
Math.atan(opposite / adjacent) // angle of a right-angle triangle in radians
var adjacent = Math.cos(radian) * hypotenuse; // leng of adjacent side
// find the point on a circle if you know the circle´s radius
var x = Math.cos(pointAngleInRadiansFromCentreOfCircle) * radius;
var y = Math.sin(pointAngleInRadiansFromCentreOfCircle) * radius;
Math.cbrt(64) // cube root of a number 4 (4 x 4 x 4)
Math.exp(xNumber) // returns e<sup>xNumber</sup> ... e == Math.E
Math.ceil() // always rounds a number up to the next largest integer
Math.ceil(1.001) // 2
Math.floor() // returns largest integer less than or equal to a given number
Math.floor(5.85) = 5
Math.floor(-5.15) = -6
const arrayA = [2, 3, 1];
Math.min(...arrayA) = 1;
Math.max(1, 3, 2) = 3;
Math.random() // returns 0.000.... - 0.99999999999
Math.random() * 3 // returns 0.000 - 2.99999999999
Math.round() // returns value of a number rounded to the nearest integer.
Math.round(0.9) // 1
Math.round(5.5) // 6
Math.round(5.05) // 5
Math.floor(Math.random() * 3) // returns 0, 1, 2
Date: 14.06.2020 - 08:38g | Global / najde všechny, nezastaví se po prvním nálezu |
m | Multiline / prohledá i v dalších řádcích |
i | Case insensitive / citlivý na velikost písmen |
x | Ignore whitespace / ignoruje všechny mezery a umožňuje vložení komentáře do regexu. Komentáře jsou označeny znakem "#". Pokud potřebujete zahrnout znak mezery ve vašem regexu musíte jej označit '\ ' |
s | Single line |
u | Unicode / \w+ již pak vybere celé slovo i když obsahuje například českou dikakritiku |
X | eXtended |
U | Ungreedy / např. a+ vybere jen první a z aaaaaa |
A | Anchor / např. a+ označí první výskyt a a všechny další a pokud jej následují holaaaahou už ne aaa |
J | Duplicate group names / regex může mít duplicitní názvy vzorů, ale každá skupina vyhledání má stále své vlastní ID. Npř. /(?<letter>a)(?<letter>b)/J Tyto dvě skupiny produkují vlastní zápas namísto jedné kombinované skupiny. ab bude rozděleno do dvou skupin. Full match bude ab |
global je klíčové slovo, které zajistí viditelnost proměnné například uvnitř funkcí.
$a = 5;
$b = 2;
function Secti()
{
global $a, $b;
$b = $a + $b;
}
Secti();
echo $b;// 7
// pred vsemi include file
$varGlob = 10;
include('some.inc');
$GLOBALS; // pole ktere obsahuje SERVER i vsechny uzivatelovi globalni promenne
function PrintFC()
{
$a = $GLOBALS['varGlob']; // ziskame globalni promennou
$GLOBALS['varGlob'] = 20; // muzeme prepsat jeji hodnotu
print $a; // 10
}
PrintFC();
print $varGlob; // 20
Editace: 14.5.2020 - 13:56
Počet článků v kategorii: 77
Url:php-array-inicializace-php