NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - intval

Trieda

Koreň \ Bez triedy

Metóda - intval

(PHP 4, PHP 5, PHP 7)

Determines the integer value of a given parameter with a conversion to a specified base (radix).

Note: Calling this function with an object given as the $var parameter will result into emitting an error of the E_NOTICE level and returning 1.

Procedurálne

  • function intval (mixed $var, int $base = 10) : int

Parametre

NázovDátový typPredvolená hodnotaPopis
$varmixed

The input value, whose integer value should be determined.

$baseint 10

The base (radix) of the numerical system in which the input value is represented.

Note: This parameter will take effect only if the input value is string.

If value 0 is passed, the resulting base will be determined automatically. The default b

Mávratovej hodnoty

Vracia: int

The resulting integer value, if conversion succeeds, 0 otherwise.

Passing an empty array will return 0, for a non-empty array will return 1.

Príklady

<?php
echo intval(11);        // Output: 11
echo intval('11');      // Output: 11
echo intval('+11');     // Output: 11
echo intval('-11');     // Output: -11
echo intval('011'); // Output: 11
echo intval(011);   // Output: 9

echo intval(1e10);  // Output: 1
echo intval('1e10');    // Output: 10000000000

echo intval(5.2);       // Output: 5

echo intval('0x1A');    // Output: 0
echo intval(0x1a);  // Output: 26

echo intval(array());   // Output: 0
echo intval(array(50)); // Output: 1

Súvisiace manuály

      Aktivity