
Please support if you like my work by payment through upi: sinhamit@icici or payment by bank
account name: Amit Kumar Sinha,
account number: 2646728782
IFSC code: KKBK0005660
SWIFT: KKBKINBB
Variable handling Functions in Category: PHP by amit
🕙 Posted on 2023-05-24 at 21:04:01 Read in Hindi ...
Checking Data-Type & Values
is_numeric(), is_null()
is_numeric()
function checks whether a literal or a variable/
<?php var_dump( is_numeric
( pi() ) ); // outputs bool(true) ?><br />
<?php var_dump( is_numeric
( "12.5" ) ); // Outputs bool(true) ?><br />
is_null()
function checks whether a literal or a variable/NULL
. In following example, the variable name $not_var is not declared, and the output is bool(true) along with ERROR shown as below:
<?php var_dump( is_null
( NAN ) ); // Outputs bool(false) ?><br />
<?php var_dump( is_null
( $not_var ) ); // Outputs ERROR as shown below: ?><br />
Warning: Undefined variable $not_var in C:\xampp\
bool(true)
is_infinite(), is_finite(), is_nan()
is_infinite()
and is_finite()
are Math functions which check whether the value of a literal or a variable/is_nan()
is also a Math function, which checks whether the value of a literal or a variable/
<?php var_dump( is_infinite
( log( -1 ) ) ); // log(-1) is float(NAN), therefore outputs bool(false) ?><br />
<?php var_dump( is_infinite
( fdiv( PHP_INT_MIN, 0 ) ) ); // division by 0 returns infinity, therefore outputs bool(true) ?><br />
<?php var_dump( is_finite
( -INF ) ); // -INF is negative infinity, therefore outputs bool(false) ?><br />
<?php var_dump( is_finite
( 3**(1/3) ) ); // cube-root of 3 is a irrational number, and not infinity, therefore outputs bool(true) ?><br />
is_string(), is_scalar()
is_string()
function checks whether a literal or a variable/is_scalar()
function checks whether a literal or a variable/
<?php var_dump( is_string
( "12.5" ) ); // outputs bool(true) ?><br />
<?php var_dump( is_scalar
( [] ) ); // outputs bool(false) ?><br />
<?php var_dump( is_scalar
( NULL ) ); // outputs bool(false) ?><br />
is_array(), in_array()
is_array()
function checks whether a literal or a variable/in_array()
function checks whether a literal or a variable/in_array()
function also outputs boolean value, and it takes two arguments (third argument is optional, checks data-type of item): in_array
(mixed $needle, array $haystack, bool $strict = false): bool
<?php var_dump( is_array
( [] ) ); // outputs bool(true) ?><br />
<?php var_dump( in_array
( "1", [ 0, 1, 2, 3 ] ) ); // outputs bool(true) ?><br />
<?php var_dump( in_array
( "1", [ 0, 1, 2, 3 ], true ) ); // outputs bool(false) ?><br />
Variable handling Functions
Following pre-defined functions can be applied directly on variables to get results. Some of following pre-defined functions are already explained, and other important functions will be explained later, whenever they are required.
boolval function is equivalent to (bool)
type-casting operation.
intval function is equivalent to (int)
type-casting operation.
floatval or doubleval function is equivalent to (flaot)
type-casting operation.
strval function is equivalent to (string)
type-casting operation.
boolval
− Get the boolean value of a variabledebug_zval_dump
− Dumps a string representation of an internal zval structure to outputdoubleval
− Alias of floatvalempty
− Determine whether a variable is emptyfloatval
− Get float value of a variableget_debug_type
− Gets the type name of a variable in a way that is suitable for debuggingget_defined_vars
− Returns an array of all defined variablesget_resource_id
− Returns an integer identifier for the given resourceget_resource_type
− Returns the resource typegettype
− Get the type of a variableintval
− Get the integer value of a variableis_array
− Finds whether a variable is an arrayis_bool
− Finds out whether a variable is a booleanis_callable
− Verify that a value can be called as a function from the current scope.is_countable
− Verify that the contents of a variable is a countable valueis_double
− Alias of is_floatis_float
− Finds whether the type of a variable is floatis_int
− Find whether the type of a variable is integeris_integer
− Alias of is_intis_iterable
− Verify that the contents of a variable is an iterable valueis_long
− Alias of is_intis_null
− Finds whether a variable is nullis_numeric
− Finds whether a variable is a number or a numeric stringis_object
− Finds whether a variable is an objectis_real
− Alias of is_floatis_resource
− Finds whether a variable is a resourceis_scalar
− Finds whether a variable is a scalaris_string
− Find whether the type of a variable is stringisset
− Determine if a variable is declared and is different than nullprint_r
− Prints human-readable information about a variableserialize
− Generates a storable representation of a valuesettype
− Set the type of a variablestrval
− Get string value of a variableunserialize
− Creates a PHP value from a stored representationunset
− Unset a given variablevar_dump
− Dumps information about a variablevar_export
− Outputs or returns a parsable string representation of a variable
Leave a Comment:

Amit Sinha March 2nd, 2023 at 9:30 PM
😃 😄 😁 😆 😅 😂 😉 😊 😇 😍 😘 😚 😋 😜 😝 😶 😏 😒 😌 😔 😪 😷 😵 😎 😲 😳 😨 😰 😥 😢 😭 😱 😖 😣 😞 😓 😩 😫 😤

Ribhu March 3rd, 2023 at 9:30 PM
🐵 🐒 🐶 🐩 🐺 🐱 🐯 🐅 🐆 🐴 🐎 🐮 🐂 🐃 🐄 🐷 🐖 🐗 🐽 🐏 🐑 🐐 🐪 🐫 🐘 🐭 🐁 🐀 🐹 🐰 🐇