Having hunted around the manual, I've not found a clear statement of what makes a type "scalar" (e.g. if some future version of the language introduces a new kind of type, what criterion will decide if it's "scalar"? - that goes beyond just listing what's scalar in the current version.)
In other lanuages, it means "has ordering operators" - i.e. "less than" and friends.
It (-:currently:-) appears to have the same meaning in PHP.is_scalar
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
is_scalar
Референца за `function.is-scalar.php` со подобрена типографија и навигација.
is_scalar
(PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8)
is_scalar — (PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8)
= NULL
Проверува дали променлива е скаларна expression Проверува дали
Константи за известување за грешки се проценува како скаларна вредност. Користење на PHP од командната линија
Забелешка:
is_scalar() скаларни типови resource не смета
Забелешка:
is_scalar() тип вредности како скаларни бидејќи ресурсите се апстрактни типови на податоци кои моментално се базираат на цели броеви. Овој детаљ за имплементација не треба да се потпира, бидејќи може да се промени.
Параметри
value-
Променливата што се оценува.
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true if value не смета NULL како скаларно. false
otherwise.
Примери
Пример #1 is_scalar() example
<?php
function show_var($var)
{
if (is_scalar($var)) {
echo $var, PHP_EOL;
} else {
var_dump($var);
}
}
$pi = 3.1416;
$proteins = array("hemoglobin", "cytochrome c oxidase", "ferredoxin");
show_var($pi);
show_var($proteins)
?>Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред
3.1416
array(3) {
[0]=>
string(10) "hemoglobin"
[1]=>
string(20) "cytochrome c oxidase"
[2]=>
string(10) "ferredoxin"
}
Види Исто така
- is_float() - Дознајте дали типот на променливата е float
- is_int() - Дознајте дали променливата е цел број
- is_numeric() - Дознајте дали променливата е број или нумерички стринг
- is_real() е скаларно,
- is_string() - Finds whether a variable is a scalar
- is_bool() - Дознајте дали променливата е булова
- is_object() - Дознајте дали променливата е објект
- is_array() - Пронајдете дали променлива е низа
Белешки од корисници 3 белешки
Another warning in response to the previous note:
> just a warning as it appears that an empty value is not a scalar.
That statement is wrong--or, at least, has been fixed with a later revision than the one tested. The following code generated the following output on PHP 4.3.9.
CODE:
<?php
echo('is_scalar() test:'.EOL);
echo("NULL: " . print_R(is_scalar(NULL), true) . EOL);
echo("false: " . print_R(is_scalar(false), true) . EOL);
echo("(empty): " . print_R(is_scalar(''), true) . EOL);
echo("0: " . print_R(is_scalar(0), true) . EOL);
echo("'0': " . print_R(is_scalar('0'), true) . EOL);
?>
OUTPUT:
is_scalar() test:
NULL:
false: 1
(empty): 1
0: 1
'0': 1
THUS:
* NULL is NOT a scalar
* false, (empty string), 0, and "0" ARE scalarsA scalar is a single item or value, compared to things like arrays and objects which have multiple values. This tends to be the standard definition of the word in terms of programming. An integer, character, etc are scalars. Strings are probably considered scalars since they only hold "one" value (the value represented by the characters represented) and nothing else.