Chapterبەش 5 · Lectureوانە 5.5

Data typesجۆرەکانی دراوە

Every PHP value has a type. Meet the eight data types, see them with var_dump(), learn the limits of integers and floats, which values count as true or false, what NULL means, and how PHP converts between types.

هەموو لە PHPـدا جۆرێکی هەیە. هەشت PHP بناسە، بە var_dump() بیانبینە، سنوورەکانی و فێربە، بزانە کام وەک true یان false دەژمێردرێن، NULL واتای چییە و PHP چۆن لە نێوان جۆرەکاندا دەگۆڕێت.

19 min read17 خولەک خوێندنەوە · 18 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Name PHP's eight data types and give an example of each.
  • Use var_dump(), gettype() and get_debug_type() to see a value's type.
  • Know the real limits of integers and why floats are not exact.
  • Predict which values become true or false.
  • Explain NULL and how it differs from the empty string.
  • Understand type juggling and convert types yourself with casts.
  • هەشت PHP ناو ببەیت و بۆ هەر یەکێکیان نموونەیەک بهێنیتەوە.
  • var_dump() و gettype() و get_debug_type() بەکاربهێنیت بۆ بینینی جۆری .
  • سنوورە ڕاستەقینەکانی بزانیت و بزانیت بۆچی ورد نین.
  • پێشبینی بکەیت کام دەبنە true یان false.
  • NULL ڕوون بکەیتەوە و جیاوازییەکەی لەگەڵ بەتاڵ.
  • لە ⁦type juggling⁩ تێبگەیت و خۆت بە cast جۆرەکان بگۆڕیت.

What is a data type?جۆری دراوە چییە؟

Every value in PHP has a type. The type says what kind of value it is (a whole number, a piece of text, yes-or-no, and so on) and what you can do with it. You can add two numbers, but adding two names makes no sense. The type of a value is called its .

هەموو لە PHPـدا جۆرێکی هەیە. جۆرەکە دەڵێت ئەو چ جۆرە شتێکە (، پارچە دەقێک، بەڵێ یان نەخێر و هتد) و چیت پێ دەکرێت. دەتوانیت دوو ژمارە کۆ بکەیتەوە، بەڵام کۆکردنەوەی دوو ناو هیچ واتایەکی نییە. بە جۆری دەوترێت .

Definitionپێناسە

The kind of a value, such as text, an , a , a date or a (true or false). It decides how the value is stored and what you can do with it, for example adding numbers or joining pieces of text. Data types are used in , and .

جۆری نرخێکە، وەک دەق، ، ، بەروار یان (ڕاست یان هەڵە). دیاری دەکات نرخەکە چۆن هەڵدەگیرێت و چی پێ دەکرێت، بۆ نموونە کۆکردنەوەی ژمارەکان یان پێکەوەلکاندنی دەقەکان. ، و هەموویان جۆری دراوە بەکاردەهێنن.

Different goods, different measuresکاڵای جیاواز، پێوانەی جیاواز

Walk through the bazaar. You count eggs: 1, 2, 12. These are whole numbers, like PHP integers. You weigh rice: 1.5 kg, a number with a fraction, like a float. You write a name on a price card: text, like a string. A shop is either open or closed: like a boolean, which is only true or false. An empty basket with nothing in it is like NULL. And a shopping list that holds many items is like an array.

بە بازاڕدا بڕۆ. هێلکە دەژمێریت: 1، 2، ⁦12⁩. ئەمانە ژمارەی بێ کەرتن، وەک لە PHPـدا. برنج دەکێشیت: ⁦1.5⁩ کیلۆ، ژمارەیەک بە کەرتەوە، وەک . ناوێک لەسەر کارتی کاڵایەک دەنووسیت: دەق، وەک . دوکانێک یان کراوەیە یان داخراوە: وەک ، کە تەنها true یان falseـە. سەبەتەیەکی بەتاڵ کە هیچی تێدا نییە وەک NULLـە. لیستێکی بازاڕکردنیش کە چەندین شت هەڵدەگرێت وەک .

Where the analogy stops workingسنووری ئەم نموونەیە

In real life the same goods can be counted and weighed. A PHP value has exactly one type at a time, although PHP can convert it to another type when needed (see type juggling).

لە ژیانی ڕاستەقینەدا هەمان کاڵا دەکرێت هەم بژمێردرێت هەم بکێشرێت. بەڵام لە PHPـدا لە هەر کاتێکدا تەنها یەک جۆری هەیە، هەرچەندە PHP دەتوانێت لە کاتی پێویستدا بیگۆڕێت بۆ جۆرێکی تر (بڕوانە گۆڕینی جۆر).

Unlike many other programming languages, PHP variables do not have to be declared. A variable's type comes from its context: from the value you put in it. The standard types include numbers, both and so-called floating-point numbers (), which can have a fraction part. Another standard type is the , which can be used for the names of things or just about any text.

جیاواز لە زۆرێک لە تر، لە PHPـدا پێویست ناکات ڕابگەیەندرێن. لە دەوروبەرەکەیەوە دێت: لەو تێیدا دادەنێیت. جۆرە ستانداردەکان ژمارە لەخۆ دەگرن، هەم و هەم ئەوانەی پێیان دەوترێت ژمارەی خاڵی جووڵاو ()، کە دەتوانن بەشی کەرتییان هەبێت. جۆرێکی ستانداردی تر ـە، کە بۆ ناوی شتەکان یان نزیکەی هەر دەقێک بەکاردێت.

What is a data type?جۆری دراوە چییە؟

The eight data typesهەشت جۆری دراوەی PHP

PHP is : it automatically gives a variable the correct data type depending on its value, so you never have to say what type a variable is (see Variables). PHP has a total of eight data types, which we use to build our variables:

PHP جۆری داوا ناکات (): خۆکارانە بەپێی ، گونجاو دەداتە ، بۆیە هەرگیز پێویست ناکات بڵێیت چ جۆرێکە (بڕوانە گۆڕاوەکان). PHP بە گشتی هەشت هەیە کە پێ دروست دەکەین:

A tree diagram. "PHP data types" branches into three groups. Scalar (one simple value): integer (22, -5), float (3.5, 1.5e3), string ("Hana", 'Erbil') and boolean (true, false). Compound (many values): array (["red", "green"], [1, 2, 3]) and object (new DateTime()). Special: NULL (null, "no value") and resource (fopen("a.txt", "r"), an open file).دارێکی پۆلێنکردن. «جۆرەکانی دراوە لە PHP» دەبێتە سێ گرووپ. سادە (یەک نرخ): ژمارەی تەواو (22، -5)، ژمارەی کەرتی (3.5، 1.5e3)، زنجیرەنووسە ("Hana"، 'Erbil') و بوولیان (true، false). ئاوێتە (چەند نرخێک): ڕیزەک (["red", "green"]، [1, 2, 3]) و ئۆبجێکت (new DateTime()). تایبەت: بێنرخ (null، «هیچ نرخێک نییە») و سەرچاوە (fopen("a.txt", "r")، فایلێکی کراوە).
The eight classic PHP data types in three groups.هەشت کلاسیکی PHP لە سێ گرووپدا.CêIT
PHP's eight data typesهەشت PHP
TypeجۆرGroupگرووپWhat it holdsچی هەڵدەگرێتExampleنموونە
(int)ScalarسادەA whole number, positive, negative or zero.ژمارەیەکی بێ کەرت، موجەب، سالب یان سفر.22
(float, double)ScalarسادەA number with a decimal point or in exponential form.ژمارەیەک بە خاڵی دەیی یان بە شێوەی توان.3.5
(string)ScalarسادەText: letters, digits, symbols.دەق: پیت، ژمارە، هێما."Hana"
(bool)ScalarسادەOnly true or false.تەنها true یان false.true
(array)CompoundئاوێتەMany values in one variable.چەندین لە یەک .["red", "green"]
(object)CompoundئاوێتەA value built from a : data together with functions. کە لە دروست دەکرێت: لەگەڵ .new DateTime()
(NULL)Specialتایبەت"No value". The only value of this type is null.«هیچ نییە». تاکە ئەم جۆرە nullـە.null
(resource)SpecialتایبەتA link to something outside PHP, such as an open file.دەستکێک بۆ شتێک لە دەرەوەی PHP، وەک کراوە.fopen("a.txt", "r")

This lecture looks closely at the four simple (scalar) types and NULL. Arrays and objects have their own lectures later in the course.

ئەم وانەیە بە وردی سەیری چوار جۆرە سادەکە و NULL دەکات. و لە دواتردا وانەی تایبەتی خۆیان هەیە.

Quick checkپشکنینی خێراWhich of these is not one of PHP's eight classic data types?کامیان یەکێک نییە لە هەشت کلاسیکیی PHP؟

Seeing the type: var_dump() and gettype()بینینی جۆر: var_dump() و gettype()

var_dump() is the best tool for learning types. It prints the type and the value of whatever you give it. For a string it also prints the length, and for an array the number of elements. Put it inside <pre> so that the browser keeps its line breaks.

var_dump() باشترین ئامرازە بۆ فێربوونی جۆرەکان. جۆر و هەر شتێک کە پێی بدەیت دەنووسێت. بۆ درێژییەکەشی دەنووسێت و بۆ ژمارەی . بیخە ناو <pre>ەوە تاکو دێڕە نوێیەکانی بپارێزێت.

One variable of each common typeیەک گۆڕاو لە هەر جۆرێکی باوtypes.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$age = 22;                      // integer
$price = 750.5;                 // float
$name = "Hana";                 // string
$isStudent = true;              // boolean
$nothing = null;                // NULL
$colors = ["red", "green"];     // array

echo "<pre>";
var_dump($age);
var_dump($price);
var_dump($name);
var_dump($isStudent);
var_dump($nothing);
var_dump($colors);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-7

PHP chooses each type from the value. We never write the type.

PHP جۆری هەر یەکێکیان لە هەڵدەبژێرێت. ئێمە هەرگیز جۆرەکە نانووسین.

Lineدێڕی 9

<pre> keeps the line breaks in the browser.

<pre> دێڕە نوێیەکان لە دەپارێزێت.

Reading var_dump() outputخوێندنەوەی var_dump()
var_dump() shows⁦var_dump()⁩ پیشانی دەداتMeaningواتا
int(22)An integer with the value 22. بە ⁦22⁩.
float(750.5)A float with the value 750.5. بە ⁦750.5⁩.
string(4) "Hana"A string 4 bytes long, then the text itself. بە درێژیی 4 ، پاشان خودی دەقەکە.
bool(true)A boolean that is true. کە trueـە.
NULLNo value.هیچ نییە.
array(2) {...}An array with 2 elements; each element is shown with its own type. بە 2 ؛ هەر بە جۆری خۆیەوە پیشان دەدرێت.

gettype() returns the type name as a string. PHP 8 also has get_debug_type(), which gives the short, modern names that you also see in error messages:

gettype() ناوی جۆرەکە وەک دەگەڕێنێتەوە. ⁦PHP 8⁩ get_debug_type()یشی هەیە، کە ناوە کورت و نوێیەکان دەدات، هەمان ئەو ناوانەی لە پەیامەکانی دەیانبینیت:

gettype() and get_debug_type()gettype() و get_debug_type()typenames.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo gettype(22) . " | " . get_debug_type(22) . "<br>";
echo gettype(750.5) . " | " . get_debug_type(750.5) . "<br>";
echo gettype("Hana") . " | " . get_debug_type("Hana") . "<br>";
echo gettype(true) . " | " . get_debug_type(true) . "<br>";
echo gettype(null) . " | " . get_debug_type(null) . "<br>";
echo gettype(["red", "green"]) . " | " . get_debug_type(["red", "green"]);
?>
Quick checkپشکنینی خێراWhat does gettype(1.5) return?gettype(1.5) چی دەگەڕێنێتەوە؟

Integers (int)ژمارە تەواوەکان (int)

An is a whole number, without a decimal point. It can be positive, negative or zero. An integer cannot contain a comma or spaces. Since PHP 7.4 you may use underscores _ to make long numbers easier to read; PHP ignores them.

ژمارەیەکی بێ کەرتە، بێ خاڵی دەیی. دەتوانێت موجەب، سالب یان سفر بێت. ناتوانێت فاریزە یان لەخۆ بگرێت. لە ⁦PHP 7.4⁩ـەوە دەتوانیت _ بەکاربهێنیت بۆ ئەوەی ژمارە درێژەکان ئاسانتر بخوێنرێنەوە؛ PHP فەرامۆشیان دەکات.

Positive, negative, zero and a big numberموجەب، سالب، سفر و ژمارەیەکی گەورەintegers.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = 25;          // positive
$b = -17;         // negative
$c = 0;           // zero
$d = 1_000_000;   // underscores make big numbers easy to read (PHP 7.4+)

echo "<pre>";
var_dump($a, $b, $c, $d);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

1_000_000 is one million. The underscores are only for people.

1_000_000 یەک ملیۆنە. تەنها بۆ مرۆڤن.

A comma or a space inside a number is a syntax error:

فاریزە یان لەناو ژمارەدا :

Wrong: a comma inside a numberنادروست: فاریزە لەناو ژمارەداpopulation.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$population = 1,000,000;

Integers (int)ژمارە تەواوەکان (int)

How big can an integer be?ژمارەی تەواو تا چەند گەورە دەبێت؟

An integer is stored in a fixed number of bytes, so it has a smallest and a largest value. PHP tells you the limits with three ready-made constants: PHP_INT_SIZE (bytes per integer), PHP_INT_MAX (largest) and PHP_INT_MIN (smallest).

لە چەند جێگیردا هەڵدەگیرێت، بۆیە بچووکترین و گەورەترین هەیە. PHP بە سێ ئامادە سنوورەکانت پێدەڵێت: PHP_INT_SIZE (ژمارەی هەر )، PHP_INT_MAX (گەورەترین) و PHP_INT_MIN (بچووکترین).

The integer limits on a 64-bit PHPسنوورەکانی ژمارەی تەواو لە PHPی ⁦64⁩-بیتیداlimits.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo PHP_INT_SIZE . "<br>";   // bytes used for one integer
echo PHP_INT_MAX . "<br>";    // the largest integer
echo PHP_INT_MIN . "<br>";    // the smallest integer

echo "<pre>";
var_dump(2147483647 + 1);     // bigger than the old 32-bit limit: still an int
var_dump(PHP_INT_MAX + 1);    // too big: PHP switches to a float
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-4

On a 64-bit PHP an integer uses 8 bytes.

لە PHPی ⁦64⁩-بیتیدا هەر 8 بەکاردەهێنێت.

Lineدێڕی 7

2147483647 + 1 is still an integer here.

⁦2147483647 + 1⁩ لێرەدا هێشتا .

Lineدێڕی 8

One more than the largest integer becomes a float, and it is no longer exact.

یەک زیاتر لە گەورەترین دەبێتە و ئیتر ورد نییە.

Quick checkپشکنینی خێراOn a 64-bit PHP, what is PHP_INT_MAX?لە PHPی ⁦64⁩-بیتیدا PHP_INT_MAX چەندە؟

Floating-point numbers (float)ژمارە کەرتییەکان (float)

A is a number with a decimal point, or a number written in exponential form. It is also called a double; in PHP the two names mean the same type. By default, PHP prints a float with the minimum number of decimal places needed.

ژمارەیەکە بە خاڵی دەیی، یان ژمارەیەک کە بە شێوەی توان نووسراوە. پێی دەوترێت doubleیش؛ لە PHPـدا ئەم دوو ناوە هەمان جۆرن. بە شێوەی بنەڕەت، PHP بە کەمترین ژمارەی پێویستی ڕەقەمی دوای خاڵ دەنووسێت.

Adding two floatsکۆکردنەوەی دوو ژمارەی کەرتیfloat.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 2.2888800;
$y = 2.2111200;
$sum = $x + $y;
echo $sum;
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-3

The trailing zeros in 2.2888800 do not matter.

سفرەکانی کۆتایی لە 2.2888800 هیچ گرنگییەکیان نییە.

Lineدێڕی 5

The sum is 4.5 exactly, so PHP prints 4.5, not 4.5000000.

کۆکەکە ڕێک ⁦4.5⁩ـە، بۆیە PHP 4.5 دەنووسێت نەک 4.5000000.

Exponential form is a short way to write very large or very small numbers: 1.5e3 means 1.5 × 10³ = 1500, and 7E-3 means 7 × 10⁻³ = 0.007. Dividing two integers also gives a float when the answer has a fraction:

شێوەی توان ڕێگایەکی کورتە بۆ نووسینی ژمارەی زۆر گەورە یان زۆر بچووک: 1.5e3 واتە ⁦1.5 × 10⁩³ = ⁦1500⁩ و 7E-3 واتە ⁦7 × 10⁩⁻³ = ⁦0.007⁩. دابەشکردنی دوو کاتێک وەڵامەکە کەرتی هەبێت دەدات:

Floats in exponential formژمارە کەرتییەکان بە شێوەی توانexponent.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = 1.5;
$b = 1.5e3;     // 1.5 × 10 to the power 3 (exponential form)
$c = 7E-3;      // 7 × 10 to the power -3
$d = 10 / 4;    // dividing can make a float

echo "<pre>";
var_dump($a, $b, $c, $d);
echo "</pre>";
echo $b . "<br>" . $c;
?>
Quick checkپشکنینی خێراWhat does var_dump(7 / 2); print?var_dump(7 / 2); چی دەنووسێت؟

PHP Float Data Type - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 75K viewsبینین · 2.5K likesلایک

Learn how big a float can be, why float maths can give tiny errors, and why comparing two floats with == is risky.

فێر دەبیت تا چەند گەورە دەبێت، بۆچی ژمێرکاری بە هەڵەی زۆر بچووک دەدات و بۆچی بەراوردکردنی دوو بە == مەترسیدارە.

Covers float limits and why floats are not exact.

باسی سنووری دەکات و بۆچی ورد نین.

Floating-point numbers (float)ژمارە کەرتییەکان (float)

Floats are not exactژمارە کەرتییەکان ورد نین

A computer stores a float in binary, and many decimal fractions (such as 0.1) cannot be stored exactly. The tiny errors usually stay hidden, but they appear when you compare floats:

بە شێوەی هەڵدەگرێت و زۆر کەرتی دەیی (وەک ⁦0.1⁩) ناتوانرێن بە وردی هەڵبگیرێن. هەڵە بچووکەکان زۆرجار شاراوە دەمێننەوە، بەڵام کاتێک بەراورد دەکەیت دەردەکەون:

0.1 + 0.2 is not exactly 0.3⁦0.1 + 0.2⁩ ڕێک ⁦0.3⁩ نییەprecision.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$total = 0.1 + 0.2;

echo "<pre>";
var_dump($total);
var_dump($total == 0.3);            // false!
var_dump(round($total, 2) == 0.3);  // true after rounding
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 6

The stored total is 0.30000000000000004, so it is not equal to 0.3.

کۆی هەڵگیراو ⁦0.30000000000000004⁩ـە، بۆیە یەکسان نییە بە ⁦0.3⁩.

Lineدێڕی 7

round($total, 2) rounds to 2 decimal places first.

round($total, 2) سەرەتا بۆ 2 ڕەقەمی دوای خاڵ نزیکی دەکاتەوە.

Stringsزنجیرەنووسەکان

A is text: a sequence of characters inside single quotes '...' or double quotes "...". Strings are used for the names of things or just about any text. They have a whole lecture of their own: Strings.

دەقە: زنجیرەیەک لە لەناو تاک '...' یان جووت "...". بۆ ناوی شتەکان یان نزیکەی هەر دەقێک بەکاردێن. وانەیەکی تەواوی تایبەت بە خۆیان هەیە: زنجیرەنووسەکان.

The length that var_dump() shows is in bytesئەو درێژییەی var_dump() پیشانی دەدات بە بایتەstrings.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$city = "Erbil";
$greeting = "سڵاو";

echo "<pre>";
var_dump($city);       // 5 letters = 5 bytes
var_dump($greeting);   // 4 Kurdish letters = 8 bytes
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

Each Kurdish letter takes 2 bytes in UTF-8, so the 4 letters of سڵاو count as 8.

هەر پیتێکی کوردی لە ⁦UTF-8⁩دا 2 دەگرێت، بۆیە 4 پیتەکەی سڵاو وەک 8 دەژمێردرێن.

Text that looks like a number, such as "22", is still a string. PHP can turn it into a number when it needs one: see type juggling.

ئەو دەقەی وەک ژمارە دەردەکەوێت، وەک "22"، هێشتا . PHP دەتوانێت لە کاتی پێویستدا بیکاتە ژمارە: بڕوانە گۆڕینی جۆر.

Quick checkپشکنینی خێراWhat does var_dump("22"); print?var_dump("22"); چی دەنووسێت؟

Booleans (bool)بوولیانەکان (bool)

A has only two possible values: true or false. Booleans answer yes-or-no questions: Is the user logged in? Is the form complete? They are the basis of every decision in a program. The words are not case-sensitive: true, TRUE and True are the same value, but lowercase is the usual style.

تەنها دوو هەیە: true یان false. وەڵامی پرسیاری بەڵێ-یان-نەخێر دەدەنەوە: ئایا چووەتە ژوورەوە؟ ئایا تەواوە؟ بنەمای هەموو بڕیارێکن لە . ئەم وشانە نین: true و TRUE و True هەمان ، بەڵام پیتی بچووک شێوازی ئاساییە.

An if statement with a booleanڕستەی if لەگەڵ بوولیانێکalways.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
if (TRUE)  print("This will always print<br>");
else       print("This will never print<br>");
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The condition is always TRUE, so the first print runs.

هەمیشە TRUEـە، بۆیە printی یەکەم جێبەجێ دەبێت.

Lineدێڕی 3

The else part never runs. (You will learn if in Conditionals.)

بەشی else هەرگیز جێبەجێ نابێت. (if لە وانەی ڕستە مەرجییەکان دەخوێنیت.)

Printing booleansنووسینی بوولیانەکانprintbool.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = true;
$b = TRUE;
$c = True;
var_dump($a === $b, $b === $c);   // all three are the same value
echo "<br>[";
echo true;      // prints 1
echo "] [";
echo false;     // prints nothing
echo "]";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

All three spellings are the same value.

هەر سێ شێوەی نووسینەکە هەمان .

Lineدێڕی 7

echo true prints 1.

echo true ژمارە 1 دەنووسێت.

Lineدێڕی 9

echo false prints nothing at all (an empty string).

echo false هیچ نانووسێت ( بەتاڵ).

PHP Boolean Data Type - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 91K viewsبینین · 2.8K likesلایک

Learn true and false, which values PHP turns into false, and why echo prints true as 1 and false as nothing.

فێری true و false دەبیت، کام دەیکاتە false و بۆچی بۆ true ژمارە 1 چاپ دەکات و بۆ false هیچ چاپ ناکات.

Also explains the conversion rules of the next screen.

هەروەها یاساکانی ڕوون دەکاتەوە، کە لە هەنگاوی داهاتوودا دێن.

Booleans (bool)بوولیانەکان (bool)

Turning other values into booleansگۆڕینی نرخەکانی تر بۆ بوولیان

When PHP needs a boolean (for example in an if), it converts other values by these rules:

کاتێک PHP پێویستی بە هەیە (بۆ نموونە لە ifدا)، تر بەم یاسایانە دەگۆڕێت:

  • A number is false if it is exactly zero (0 or 0.0), and true otherwise, including negative numbers.
  • A string is false if it is empty ("") or exactly the string "0", and true otherwise. So "0.0", " " and even "false" are true!
  • NULL is always false.
  • An array is false if it is empty ([]), and true if it has at least one element.
  • A valid resource is true. (But some functions that normally return a resource return false when they fail.)
  • Do not use a float as a boolean. A calculation that should give zero may leave a tiny rounding error, and then the result counts as true.
  • ژمارە ئەگەر ڕێک سفر بێت (0 یان 0.0) falseـە، ئەگەرنا trueـە، ژمارە سالبەکانیش.
  • ئەگەر بەتاڵ بێت ("") یان ڕێک "0" بێت falseـە، ئەگەرنا trueـە. کەواتە "0.0" و " " و تەنانەت "false"یش trueن!
  • NULL هەمیشە falseـە.
  • ئەگەر بەتاڵ بێت ([]) falseـە و ئەگەر لانیکەم هەبێت trueـە.
  • دروست trueـە. (بەڵام هەندێک کە بە ئاسایی دەگەڕێننەوە، کاتێک سەرناکەون false دەگەڕێننەوە.)
  • وەک بەکارمەهێنە. ژمێرکارییەک کە دەبێت سفر بدات لەوانەیە هەڵەیەکی زۆر بچووکی نزیککردنەوە بهێڵێتەوە و ئەو کاتە ئەنجامەکە وەک true دەژمێردرێت.
Two panels. Left, "These become false": false, 0, 0.0, "" (empty string), "0", null and [] (empty array). Right, "Everything else is true", with surprising examples: -1, 0.1, "0.0", " " (a space), "false", [0] and "Hana".دوو بەش. لای چەپ، «ئەمانە دەبنە false»: false، 0، 0.0، "" (زنجیرەنووسەی بەتاڵ)، "0"، null و [] (ڕیزەکی بەتاڵ). لای ڕاست، «هەموو شتێکی تر دەبێتە true»، بە چەند نموونەیەکی سەرسوڕهێنەر: -1، 0.1، "0.0"، " " (بۆشاییەک)، "false"، [0] و "Hana".
Only a short list of values becomes false. Everything else is true.تەنها لیستێکی کورت لە دەبنە false. هەموو شتێکی تر trueـە.CêIT
Checking the rules with (bool)پشکنینی یاساکان بە (bool)tobool.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
var_dump((bool) 0);        // the number zero
var_dump((bool) 0.0);      // zero as a float
var_dump((bool) 42);       // any other number
var_dump((bool) -1);       // negative numbers too
var_dump((bool) "");       // the empty string
var_dump((bool) "0");      // the string "0"
var_dump((bool) "0.0");    // not exactly "0"
var_dump((bool) " ");      // a space is not empty
var_dump((bool) "false");  // any other text
var_dump((bool) null);     // NULL
var_dump((bool) []);       // an empty array
var_dump((bool) [0]);      // an array with one element
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-13

(bool) converts a value to a boolean, so var_dump() shows what PHP decides.

(bool) دەگۆڕێت بۆ ، بۆیە var_dump() پیشان دەدات PHP چ بڕیارێک دەدات.

Quick checkپشکنینی خێراWhich value is false when converted to a boolean?کام کاتێک دەگۆڕدرێت بۆ دەبێتە false؟

Why not use a float as a boolean? Here a sum that should be exactly zero is not, so PHP treats it as true:

بۆچی وەک بەکارنەهێنین؟ لێرەدا کۆیەک کە دەبێت ڕێک سفر بێت سفر نییە، بۆیە PHP وەک true مامەڵەی لەگەڵ دەکات:

A float that should be zeroژمارەیەکی کەرتی کە دەبێت سفر بێتfloatbool.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 0.1 + 0.2 - 0.3;      // should be zero...
var_dump($x);
if ($x) {
    echo "PHP thinks this is TRUE";
} else {
    echo "PHP thinks this is FALSE";
}
?>

NULLبێنرخ (NULL)

NULL is a special type that has only one value: null. It means "no value". Like true and false, it is not case-sensitive: $my_var = null; is the same as $my_var = NULL;.

NULL جۆرێکی تایبەتە کە تەنها یەک هەیە: null. واتای «هیچ نییە» دەدات. وەک true و false، نییە: $my_var = null; هەمان $my_var = NULL;ـە.

A variable is NULL when you assign null to it, or when you try to use a variable that does not exist (then PHP also shows a warning, see Variables). The function isset() returns false for a variable that holds NULL.

دەبێتە NULL کاتێک nullی تێدا دادەنێیت، یان کاتێک هەوڵ دەدەیت بەکاربهێنیت کە بوونی نییە (ئەو کاتە PHP پیشان دەدات، بڕوانە گۆڕاوەکان). isset() بۆ کە NULLی تێدایە false دەگەڕێنێتەوە.

NULL, isset() and the empty stringNULL، isset() و زنجیرەنووسەی بەتاڵnull.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
$my_var = null;
$other = NULL;               // NULL is not case-sensitive
var_dump($my_var);
var_dump($my_var === $other);
var_dump(isset($my_var));    // false: the variable holds NULL
$count = 0;
var_dump(isset($count));     // true: 0 is a real value
var_dump(null === "");       // not identical
var_dump(null == "");        // but equal in a loose comparison
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-4

null and NULL are the same value.

null و NULL هەمان .

Lineدێڕی 7

isset() is false: the variable holds NULL.

isset() falseـە: NULLی تێدایە.

Lineدێڕی 9

0 is a real value, so isset() is true.

0 ڕاستەقینەیە، بۆیە isset() trueـە.

Lineدێڕی 10-11

null and "" are not identical (===), although the loose comparison == says they are equal.

null و "" وەک یەک نین (===)، هەرچەندە بەراوردی شل == دەڵێت یەکسانن.

Quick checkپشکنینی خێراAfter $city = null;, what does var_dump(isset($city)); print?دوای $city = null;، var_dump(isset($city)); چی دەنووسێت؟

You can empty a variable by assigning null, and test for it with is_null(). unset() goes one step further: it removes the variable completely.

دەتوانیت بە دانانی null بەتاڵ بکەیتەوە و بە is_null() تاقیی بکەیتەوە. unset() هەنگاوێک زیاتر دەڕوات: بە تەواوی لادەبات.

empty.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$city = "Duhok";
$city = null;        // empty the variable

echo "<pre>";
var_dump($city);
var_dump(is_null($city));
echo "</pre>";
?>
unset.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$phone = "0750 000 0000";
unset($phone);           // remove the variable completely
var_dump(isset($phone));
?>
PHP Null Data Type - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 66K viewsبینین · 2.1K likesلایک

Learn what null means, when a variable becomes null, how var_dump() shows it, and what null becomes when you cast it.

فێر دەبیت چییە، کەی دەبێتە null، var_dump() چۆن پیشانی دەدات و null دەبێتە چی کاتێک دەیگۆڕیت بۆ جۆرێکی تر.

Arrays, objects and resourcesڕیزەکەکان، ئۆبجێکتەکان و سەرچاوەکان

  • An holds many values in one variable, for example a list of names. You met one in the var_dump() example above; arrays have three lectures of their own, starting with Arrays.
  • An is a value built from a . It keeps data and functions together. new DateTime() makes a date object; later, a MySQL connection made with mysqli will also be an object.
  • A is a special handle to something outside PHP, such as an open file or a network stream. Since PHP 8 many old resources have been replaced by objects.
  • چەندین لە یەک هەڵدەگرێت، بۆ نموونە لیستێک لە ناو. لە نموونەکەی var_dump()ی سەرەوەدا یەکێکت بینی؛ سێ وانەی تایبەتیان هەیە، کە بە ڕیزەکەکان دەست پێدەکەن.
  • کە لە دروست دەکرێت. و پێکەوە دەهێڵێتەوە. new DateTime() بەروار دروست دەکات؛ دواتر کە بە mysqli دروست دەکرێت دەبێتە .
  • دەستکێکی تایبەتە بۆ شتێک لە دەرەوەی PHP، وەک کراوە یان ڕەوتێکی تۆڕ (stream). لە ⁦PHP 8⁩ـەوە زۆرێک لە بە گۆڕدراون.
An object and a resourceئۆبجێکتێک و سەرچاوەیەکothers.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$today = new DateTime("2026-10-16");   // an object
$file = fopen("php://memory", "r");    // an open stream: a resource

echo gettype($today) . " | " . get_class($today) . "<br>";
echo gettype($file) . " | " . get_resource_type($file);
?>

Type juggling: automatic conversionگۆڕینی جۆر بە شێوەی خۆکار

Because PHP is loosely typed, it converts values automatically when an operator needs a certain type. This is called type juggling (automatic ). The + operator needs numbers; the . operator needs strings:

لەبەر ئەوەی PHP جۆری داوا ناکات، کاتێک پێویستی بە جۆرێکی دیاریکراوە، بە شێوەی خۆکار دەگۆڕێت. بەمە دەوترێت ⁦type juggling⁩ ( خۆکار). + پێویستی بە ژمارەیە؛ . پێویستی بە :

PHP converts types by itselfPHP خۆی جۆرەکان دەگۆڕێتjuggling.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
var_dump("5" + 3);      // string "5" becomes the number 5
var_dump("5" . 3);      // the dot joins text: 3 becomes "3"
var_dump("2.5" * 2);    // a numeric string becomes a float
var_dump(10 / 2);       // division that comes out even: int
var_dump(7 / 2);        // division with a remainder: float
var_dump(5 + 2.0);      // int + float gives a float
var_dump(true + 1);     // true counts as 1
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

The string "5" becomes the number 5, so the answer is the integer 8.

"5" دەبێتە ژمارە 5، بۆیە وەڵامەکە 8ـە.

Lineدێڕی 4

The dot joins text, so 3 becomes "3" and the result is the string "53".

خاڵ دەق دەلکێنێت، بۆیە 3 دەبێتە "3" و ئەنجامەکە "53"ـە.

Lineدێڕی 6-7

10 / 2 divides evenly and stays an integer; 7 / 2 has a fraction and becomes a float.

⁦10 / 2⁩ بە تەواوی دابەش دەبێت و دەمێنێتەوە؛ ⁦7 / 2⁩ کەرتی هەیە و دەبێتە .

Lineدێڕی 9

true counts as 1 in arithmetic.

true لە ژمێرکاریدا وەک 1 دەژمێردرێت.

Quick checkپشکنینی خێراWhat does var_dump("5" . 3); print?var_dump("5" . 3); چی دەنووسێت؟

A string that only starts with a number is converted using that number, but PHP warns you:

کە تەنها بە ژمارە دەست پێدەکات، بەو ژمارەیە دەگۆڕدرێت، بەڵام PHP ئاگادارت دەکاتەوە:

"10 apples" + 5"10 apples" + 5apples.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$total = "10 apples" + 5;
var_dump($total);
?>

Text that is not a number at all cannot be used in arithmetic. In PHP 8 this is a TypeError, a fatal error that stops the script. (PHP 7 only warned and used 0.)

دەقێک کە هەرگیز ژمارە نییە ناتوانرێت لە ژمێرکاریدا بەکاربهێنرێت. لە ⁦PHP 8⁩ـدا ئەمە TypeErrorـە، کە ڕادەگرێت. (⁦PHP 7⁩ تەنها ئاگاداری دەکردەوە و 0ی بەکاردەهێنا.)

"ten" + 5"ten" + 5ten.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$total = "ten" + 5;
var_dump($total);
echo "This line never runs.";
?>

Converting a type yourselfگۆڕینی جۆر بە دەستی خۆت

To convert a value on purpose, put the type name in brackets before it: (int), (float), (string), (bool) or (array). This is called casting. The functions intval(), floatval(), strval() and boolval() do the same job.

بۆ گۆڕینی بە مەبەست، ناوی جۆرەکە لەناو کەوانەدا پێش بنووسە: (int)، (float)، (string)، (bool) یان (array). بەمە دەوترێت casting. intval() و floatval() و strval() و boolval() هەمان کار دەکەن.

Casting between typesگۆڕین لە نێوان جۆرەکانداcasting.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo "<pre>";
var_dump((int) "42");       // string to integer
var_dump((int) 3.99);       // float to integer: the fraction is cut off
var_dump((float) "3.14");   // string to float
var_dump((string) 25);      // integer to string
var_dump((bool) "hello");   // string to boolean
var_dump(intval("12abc"));  // reads the number at the start
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

(int) cuts off the fraction; it does not round. 3.99 becomes 3.

(int) بەشی کەرتی دەبڕێت؛ نزیکی ناکاتەوە. ⁦3.99⁩ دەبێتە 3.

Lineدێڕی 8

intval() reads the number at the start of the text and ignores the rest.

intval() ئەو ژمارەیەی لە سەرەتای دەقەکەدایە دەخوێنێتەوە و باقییەکەی فەرامۆش دەکات.

Quick checkپشکنینی خێراWhat does var_dump((int) 9.99); print?var_dump((int) 9.99); چی دەنووسێت؟

settype() changes the type of the variable itself:

settype() جۆری خودی دەگۆڕێت:

settype.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$value = 100;
echo gettype($value) . "<br>";
settype($value, "string");
echo gettype($value) . "<br>";
var_dump($value);
?>

Checking a type: the is_ functions

پشکنینی جۆر: کردارەکانی is_

Type-checking functions پشکنینی جۆر
FunctionReturns true when the value is…true دەگەڕێنێتەوە کاتێک …
is_int($x)an integer
is_float($x)a float
is_string($x)a string
is_bool($x)a boolean
is_array($x)an array
is_null($x)NULLNULLـە
is_numeric($x)a number, or a string that looks like a number (such as "22")ژمارەیە، یان کە وەک ژمارە دەردەکەوێت (وەک "22")
A form value is a string until you convert itنرخێکی فۆرم زنجیرەنووسەیە تا خۆت دەیگۆڕیتcheck.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$age = "22";

echo "<pre>";
var_dump(is_int($age));      // false: it is text
var_dump(is_string($age));   // true
var_dump(is_numeric($age));  // true: the text looks like a number
$age = (int) $age;
var_dump(is_int($age));      // true now
echo "</pre>";
?>

Common mistakesهەڵە باوەکان

Common mistakes with typesهەڵە باوەکان لەگەڵ جۆرەکاندا
MistakeهەڵەWhat really happensبە ڕاستی چی ڕوودەدات
Writing 1,000 or 1 000 in codeنووسینی 1,000 یان 1 000 لە کۆدداA parse error. Write 1000 or 1_000.. بنووسە 1000 یان 1_000.
Believing the largest integer is 2,147,483,647باوەڕ بەوەی گەورەترین ⁦2,147,483,647⁩ـەThat is the 32-bit limit. On 64-bit PHP use PHP_INT_MAX.ئەوە سنووری ⁦32⁩-بیتە. لە PHPی ⁦64⁩-بیتیدا PHP_INT_MAX بەکاربهێنە.
Comparing floats with ==بەراوردکردنی بە ==0.1 + 0.2 == 0.3 is false. Round first.0.1 + 0.2 == 0.3 falseـە. سەرەتا نزیکی بکەرەوە.
Thinking "0.0" or "false" is falseبیرکردنەوە لەوەی "0.0" یان "false" falseـنBoth are true. Only "" and "0" are false strings.هەردووکیان trueن. لە نێوان تەنها "" و "0" falseن.
Treating null and "" as identicalبە یەک زانینی null و ""null === "" is false; only the loose == says they are equal.null === "" falseـە؛ تەنها ==ی شل دەڵێت یەکسانن.
Expecting (int) 3.99 to give 4چاوەڕوانی ئەوەی (int) 3.99 بکاتە 4It gives 3. Use round() to round.3 دەدات. بۆ نزیککردنەوە round() بەکاربهێنە.
Writing 017 for seventeenنووسینی 017 بۆ حەڤدەA leading zero means octal: 017 is 15.سفری سەرەتا واتە هەشتی: 017 دەکاتە ⁦15⁩.
Doing arithmetic with text like "ten"ژمێرکاری لەگەڵ دەقی وەک "ten"PHP 8 throws a TypeError and stops.⁦PHP 8⁩ TypeError فڕێ دەدات و دەوەستێت.
Writing a "comment" after ?>نووسینی «» دوای ?>It is printed as text on the page.وەک دەق لەسەر دەنووسرێت.

Practiceڕاهێنان

Exercises

ڕاهێنانەکان

ExerciseڕاهێنانA string, an integer and a floatزنجیرەنووسەیەک، ژمارەیەکی تەواو و ژمارەیەکی کەرتی

This is exercise 3 of the course's "practise on your own computer" list: make a string, an integer and a float, and print all three. Then use var_dump() to prove that PHP chose the right type for each one.

ئەمە ڕاهێنانی سێیەمی لیستی «لەسەر خۆت ڕاهێنان بکە»ی کۆرسەکەیە: ، و دروست بکە و هەر سێکیان بنووسە. پاشان var_dump() بەکاربهێنە بۆ ئەوەی بیسەلمێنیت PHP جۆری دروستی بۆ هەر یەکێکیان هەڵبژاردووە.

Show answerوەڵامەکە پیشان بدە
three-types.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$city = "Sulaymaniyah";   // a string
$students = 35;           // an integer
$height = 1.75;           // a float

echo $city . "<br>";
echo $students . "<br>";
echo $height . "<br>";

echo "<pre>";
var_dump($city, $students, $height);
echo "</pre>";
?>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-4

No type is written: the values decide the types.

هیچ جۆرێک نانووسرێت: جۆرەکان دیاری دەکەن.

Lineدێڕی 11

var_dump() takes several values at once.

var_dump() چەند پێکەوە وەردەگرێت.

ExerciseڕاهێنانPredict var_dump()var_dump() پێشبینی بکە

Write down what var_dump() prints for each value, then check your answers with PHP: 25, -2.5, "25", 25 / 5, "7" + 3, "7" . 3, false, null.

بنووسە var_dump() بۆ هەر یەکێک لەم چی دەنووسێت، پاشان وەڵامەکانت بە PHP تاقی بکەرەوە: 25، -2.5، "25"، 25 / 5، "7" + 3، "7" . 3، false، null.

Show answerوەڵامەکە پیشان بدە
Valuevar_dump() prints⁦var_dump()⁩ دەنووسێت
25int(25)
-2.5float(-2.5)
"25"string(2) "25"
25 / 5int(5)
"7" + 3int(10)
"7" . 3string(2) "73"
falsebool(false)
nullNULL
ExerciseڕاهێنانTrue or false?true یان false؟

For each value, decide whether it counts as true or false in an if: 0, "0", "", "no", 0.0, [], ["a"], null, -3.

بۆ هەر یەکێک لەم ، بڕیار بدە لە ifدا وەک true دەژمێردرێت یان false: 0، "0"، ""، "no"، 0.0، []، ["a"]، null، -3.

Show answerوەڵامەکە پیشان بدە

False: 0, "0", "", 0.0, [], null. True: "no" (a non-empty string), ["a"] (an array with an element) and -3 (a non-zero number).

false: 0، "0"، ""، 0.0، []، null. true: "no" ( نابەتاڵ)، ["a"] ( بە ) و -3 (ژمارەیەکی جیاواز لە سفر).

ExerciseڕاهێنانFix the price checkپشکنینی نرخی کاڵا چاک بکە

A shop program adds 0.1 and 0.2 and then checks if ($total == 0.3). The check fails. Explain why, and change the condition so that it works.

دوکانێک 0.1 و 0.2 کۆ دەکاتەوە و پاشان if ($total == 0.3) دەپشکنێت. پشکنینەکە سەرناکەوێت. ڕوونی بکەرەوە بۆچی و بگۆڕە تاکو کار بکات.

Show answerوەڵامەکە پیشان بدە

Floats are stored in binary and are not exact: the total is really 0.30000000000000004. Round before comparing: if (round($total, 2) == 0.3). Even better, keep money as whole numbers of the smallest unit.

بە شێوەی هەڵدەگیرێن و ورد نین: کۆکە لە ڕاستیدا ⁦0.30000000000000004⁩ـە. پێش بەراوردکردن نزیکی بکەرەوە: if (round($total, 2) == 0.3). باشتریش ئەوەیە پارە وەک ژمارەی تەواوی بچووکترین یەکە هەڵبگریت.

precision.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$total = 0.1 + 0.2;

echo "<pre>";
var_dump($total);
var_dump($total == 0.3);            // false!
var_dump(round($total, 2) == 0.3);  // true after rounding
echo "</pre>";
?>

Reviewپێداچوونەوە

Review questionsپرسیارەکانی پێداچوونەوە
Do PHP variables need a type declaration?ئایا گۆڕاوەکانی PHP پێویستیان بە ڕاگەیاندنی جۆر هەیە؟

No. PHP is loosely typed: the type comes from the value you assign.

نەخێر. PHP جۆر داوا ناکات (): جۆرەکە لەو دێت کە دایدەنێیت.

Name PHP's eight classic data types.هەشت جۆری دراوەی کلاسیکی PHP ناو ببە.

Integer, float, string, boolean (scalar); array, object (compound); NULL, resource (special).

، ، ، (سادە)؛ ، (ئاوێتە)؛ NULL، (تایبەت).

How do you see the type of a value?چۆن جۆری نرخێک دەبینیت؟

var_dump() shows type and value; gettype() and get_debug_type() return the type name.

var_dump() جۆر و پیشان دەدات؛ gettype() و get_debug_type() ناوی جۆرەکە دەگەڕێننەوە.

What are the integer limits on today's PHP?سنوورەکانی ژمارەی تەواو لە PHPی ئەمڕۆدا چین؟

On 64-bit PHP: PHP_INT_MIN = -9223372036854775808 and PHP_INT_MAX = 9223372036854775807. Bigger results become floats.

لە PHPی ⁦64⁩-بیتیدا: PHP_INT_MIN = ⁦-9223372036854775808⁩ و PHP_INT_MAX = ⁦9223372036854775807⁩. ئەنجامی گەورەتر دەبنە .

Why should you not compare floats with ==?بۆچی نابێت ژمارە کەرتییەکان بە == بەراورد بکەیت؟

Floats are approximate. 0.1 + 0.2 is 0.30000000000000004, not 0.3. Round first.

نزیکەیین. 0.1 + 0.2 دەکاتە ⁦0.30000000000000004⁩ نەک ⁦0.3⁩. سەرەتا نزیکی بکەرەوە.

Which values become false?کام نرخانە دەبنە false؟

false, 0, 0.0, "", "0", null and an empty array []. Everything else is true.

false، 0، 0.0، ""، "0"، null و بەتاڵ []. هەموو شتێکی تر trueـە.

What is NULL, and what does isset() say about it?NULL چییە و isset() چی دەربارەی دەڵێت؟

NULL is the type with the single value null, meaning "no value". isset() returns false for a variable that is NULL.

NULL ئەو جۆرەیە کە تەنها یەک هەیە، null، بە واتای «هیچ نییە». isset() بۆ کە NULL بێت false دەگەڕێنێتەوە.

What is type juggling, and when does it fail?⁦type juggling⁩ چییە و کەی سەرناکەوێت؟

PHP converts types automatically, for example "5" + 3 gives 8. It fails for text that is not a number: "ten" + 5 throws a TypeError in PHP 8.

PHP جۆرەکان خۆکارانە دەگۆڕێت، بۆ نموونە "5" + 3 دەکاتە 8. بۆ دەقێک کە ژمارە نییە سەرناکەوێت: "ten" + 5 لە ⁦PHP 8⁩ـدا TypeError فڕێ دەدات.

How do you convert a type on purpose?چۆن بە مەبەست جۆرێک دەگۆڕیت؟

With a cast such as (int) or (string), with intval()/strval(), or with settype().

بە cast وەک (int) یان (string)، بە intval()/strval()، یان بە settype().

Key points

خاڵە سەرەکییەکان

  • PHP chooses a type from each value; you never declare it.
  • Integers are whole numbers (64-bit today); floats have a fraction and are approximate.
  • Booleans are true/false; a short list of values (0, "", "0", null, []…) becomes false.
  • NULL means "no value"; isset() is false for it, and null is not identical to "".
  • var_dump() is your best friend for seeing types.
  • PHP juggles types automatically, but convert user input yourself with casts.
  • PHP جۆری هەر خۆی هەڵدەبژێرێت؛ تۆ هەرگیز ڕایناگەیەنیت.
  • ژمارەی بێ کەرتن (ئەمڕۆ ⁦64⁩-بیت)؛ کەرتیان هەیە و نزیکەیین.
  • true/falseن؛ لیستێکی کورت لە (0، ""، "0"، null، []…) دەبنە false.
  • NULL واتە «هیچ نییە»؛ isset() بۆی falseـە و null وەک "" نییە.
  • var_dump() باشترین هاوڕێتە بۆ بینینی جۆرەکان.
  • PHP جۆرەکان خۆکارانە دەگۆڕێت، بەڵام خۆت بە cast بگۆڕە.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

PHP Data Types - Typecasting Overview & How It Works - Full PHP 8 TutorialProgram With Gio · Englishئینگلیزی · 140K viewsبینین · 3.8K likesلایک

A short tour of PHP data types: see types with var_dump() and gettype(), and how PHP changes types by itself or by casting.

ناساندنێکی کورتی : جۆرەکان بە var_dump() و gettype() دەبینیت و چۆن جۆر دەگۆڕێت، خۆکارانە یان بە casting.

Fast-paced. The type-hinting part uses functions, which you learn later.

ڤیدیۆکە خێرا دەڕوات. بەشی type hinting بەکاردەهێنێت، کە دواتر فێریان دەبیت.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Constants and variable scopeنەگۆڕەکان و مەودای گۆڕاوەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.