Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

🐘 Mukammal PHP Dasturlash Tili Qollanmasi (Full Reference Docs)

Ushbu hujjat PHP (Hypertext Preprocessor) dasturlash tili bo'yicha eng muhim tushunchalar, zamonaviy PHP 8.x imkoniyatlari, OOP (Ob'ektga Yo'naltirilgan Dasturlash) va ilg'or amaliyotlarni o'z ichiga olgan to'liq qo'llanmadir.


πŸ“‹ Mundarija

  1. PHP Kirish va Sintaksis
  2. O'zgaruvchilar va Ma'lumot Turlari
  3. Massivlar (Arrays) bilan Ishlash
  4. Funksiyalar va Arrow Functions
  5. OOP (Object-Oriented Programming)
  6. PHP 8+ Yangi Imkoniyatlari
  7. Exception & Error Handling
  8. cURL & HTTP REST API So'rovlari

1. PHP Kirish va Sintaksis

PHP β€” bu asosan veb-dasturlash va backend tizimlar yaratish uchun mo'ljallangan mashhur skript tilidir.

<?php
// Oddiy konsolga chiqarish
echo "Hello, World!\n";

2. O'zgaruvchilar va Ma'lumot Turlari

PHP da o'zgaruvchilar $ belgisi bilan boshlanadi va PHP dinamik tiplangan til hisoblanadi.

<?php

$name = "Ozodbek";         // String
$age = 24;                 // Integer
$price = 99.99;            // Float
$isDeveloper = true;       // Boolean
$skills = ['PHP', 'Go'];   // Array
$nothing = null;           // NULL

3. Massivlar (Arrays) bilan Ishlash

PHP da massivlar juda kuchli ma'lumot tuzilmasi hisoblanib, u ham indeksli, ham assotsiativ bo'lishi mumkin.

<?php

// Assotsiativ massiv
$user = [
    "id" => 1,
    "name" => "Ozodbek",
    "role" => "Backend Developer"
];

// Massiv metodlari
array_push($user, "Laravel"); // Element qo'shish
$keys = array_keys($user);    // Kalitlarni olish

4. Funksiyalar va Arrow Functions

PHP 7.4+ va PHP 8.0+ versiyalarida qisqa arrow funksiyalar va tip ko'rsatmalaridan foydalanish mumkin.

<?php

// Qisqa arrow function
$numbers = [1, 2, 3, 4, 5];
$squared = array_map(fn($n) => $n * $n, $numbers);

// Aniq tiplarga ega funksiya
function calculateTotal(float $price, int $quantity): float {
    return $price * $quantity;
}

5. OOP (Object-Oriented Programming)

Zamonaviy PHP to'liq Ob'ektga Yo'naltirilgan Dasturlashni (OOP) qo'llab-quvvatlaydi.

<?php

interface NotificationInterface {
    public function send(string $message): bool;
}

abstract class BaseUser {
    public function __construct(protected string $email) {}
}

class User extends BaseUser implements NotificationInterface {
    public function send(string $message): bool {
        // Xabar yuborish mantiqi
        return true;
    }
}

6. PHP 8+ Yangi Imkoniyatlari

Constructor Property Promotion & Named Arguments

<?php

class Product {
    public function __construct(
        public int $id,
        public string $name,
        public float $price = 0.0
    ) {}
}

// Named arguments yordamida obyekt yaratish
$item = new Product(id: 101, name: "Laptop", price: 1200.50);

Match Expression (switch o'rniga)

<?php

$statusCode = 200;

$message = match ($statusCode) {
    200, 201 => 'Muvaffaqiyatli bajarildi',
    400 => 'Bad Request',
    404 => 'Topilmadi',
    500 => 'Server xatoligi',
    default => 'Noma'lum status',
};

7. Exception & Error Handling

<?php

try {
    $file = fopen("non_existent_file.txt", "r");
    if (!$file) {
        throw new Exception("Fayl topilmadi!");
    }
} catch (Exception $e) {
    echo "Xatolik yuz berdi: " . $e->getMessage();
} finally {
    echo "\nJarayon yakunlandi.";
}

8. cURL & HTTP REST API So'rovlari

PHP yordamida tashqi API larga JSON so'rov yuborish:

<?php

$url = "https://api.example.com/data";
$payload = json_encode(["key" => "value"]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Accept: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);

About

php ga bag'ishlangan

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors