ვნახეთ
ტიპები
ცვლადები
კონსტანტა
ოპერატორები
კონტროლი
ჩამოვტვირთეთ PHP
windows.php.net/download
შეგიძლიათ ამ ლინკით ისარგებლოთ
შემდეგ d ზე გადავიტანეთ PHP არქივი და
CMD Si D:\php
php -v (ვერსია შევამოწეთ)
მერე კი აღმოვაჩინე dir *.php
https://docs.google.com/document/d/1WF0g1nSGlpAyleVkvnu6ZSxihYiQg3zOaaejg6nIY7s/edit
კითხვები include или require,, case da if აგრეტვე ტერნარული ოპერატორების
7FPbp3
vFGhxq
Lesson 2: Tasks
Find errors in examples:
1. Variables
// China's circus
$params = [];
if ($fileField = isset($params[0]) ? $params[0] : false){
echo “work”;
}
---------------------------------------------------------------------------------
2. Loop
function getLastItemName( $items ) {
$lastItemName = '';
foreach( $items as $item ) {
$lastItemName = $item;
}
//return $lastItemName;
retrurn $items[sizeof($items)-1];
}
$last_param = getLastItemName([1,2,3,4,5,6]);
---------------------------------------------------------------------------------
3. Loop
$temp = [1,2,3,4,5,6];
foreach ($temp as $var) {
$temp = $var;
break;
}
print $
gasworebuli
$temp = [1,2,3,4,5,6];
foreach ($temp as $var) {
$temp = $var;
break;
}
print $temp;
---------------------------------------------------------------------------------
4.
function api($method,$params=false) {
if (!$params) $params = array();
ცვლადი იცვლის ტიპს
---------------------------------------------------------------------------------
5.
if (!$subscription) {
return $this->redirect(['action' => 'cancel_success']);
throw new BadRequestException();
}
---------------------------------------------------------------------------------
6.
function checkRus($str)
{
$result = true;
$eng = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
for ($i = 0; $i < strlen($str); $i++) {
if (in_array($str[$i], $eng)) {
$result = false;
break;
}
}
return $result;
}
---------------------------------------------------------------------------------
7.
<?php
if (isset($cache[$domain_id]) && isset($cache[$domain_id]) && !empty($cache[$domain_id])) {
return $cache[$domain_id];
}
?>
davaleba
1. net smisla obiavliat novuiu funqciu
2. nada ubrat $is_phone == true eto virajenie posle $is_phone = 1; vsegda istino
ia ne uveren zacem tam stolko praverki raz pered praverkoi stoto prisvaivaem
i ia ubral vse vnutri kaviCkax if :) dumau oni lishnie. vot kod s primeneniem ternarnogo operatora
$is_phone = 1;
$phone_set = ($is_phone == 1 )?1:0;
3. if () viraJenia vsegda isttino no on pustoi, (naverno potom dobaviat....
Account isn't active.' lisni apostrof
zachem die; iteracia vseje zakoncheno (esli eto funqcia, i dalshe idiot kod, die prekratit rabotu koda
4 v funqcii hash pervi parametr algoritm xeshirovania napr: "md5", "sha256", "haval160,4" itgd. zdes ukazan sha256, kotori sostait iz 64 simvolov. tem samim eto chislo vsegda bolshe 5.
tem samim mi nikagda ne polucim preduprejdenie ob korotkom parole
5 v funqcii checkData nicevo ne proisxodit. nezavisima ot etovo on vsegda vozvraSaet false :)
a funqcia chek (), kotori vizivaet checkdata() toje nezavisimo ot koda vsegda budet vozvrashat 'wrong data'
:)
6. function isHidden () { bla bla bla.....
(bolean) $ret =.....;
return $rest;
} if (isHidden() === true) { return true; } else { return false; }
7. for ($i = 5; $i < 11; $i++) { //other code
8 . // foreach ($relations as $relation) {
$structured_relations[$relation['status_name']][] = [
'id' => $relation['sl_id'],
'status' => $relation['status'],
'status_name' => $relation['status_name'],
'parent' => $relation['parent'],
'parent_name' => $relation['parent_name'],
'customer' => $relation['customer'],
'provider' => $relation['provider'],
'admin' => $relation['admin'],
];
// }
return $structured_relations;
'id' => $relation['sl_id'],
'status' => $relation['status'],
'status_name' => $relation['status_name'],
'parent' => $relation['parent'],
'parent_name' => $relation['parent_name'],
'customer' => $relation['customer'],
'provider' => $relation['provider'],
'admin' => $relation['admin'],
];
// }
return $structured_relations;
9 vnutri funqcii ne obiavlen masiv.....
<?php function counter(){ $i = 0; $person = array ( "treniner" => "Yurii", "student1" => "Levan", "student2" => "Dato", ); echo " array size equal "; echo count($person); echo ". also, we can count it with Function: \n"; foreach($person as &$val){ $i++; } return $i; } echo counter(); ?>
10. ia ne znau zacem var_dump i ne xvataet figurnie skobki { }
function is_true($value){ if($value < 11){ return true;} else { return $false; } } is_true(8);
No comments:
Post a Comment