mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 17:08:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@36552 c90b9560-bf6c-de11-be94-00142212c4b1
1010 lines
29 KiB
XML
1010 lines
29 KiB
XML
<reference id="ref.var">
|
|
<title>Variable Functions</title>
|
|
<titleabbrev>Variables</titleabbrev>
|
|
|
|
<refentry id="function.doubleval">
|
|
<refnamediv>
|
|
<refname>doubleval</refname>
|
|
<refpurpose>Get double value of a variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>double <function>doubleval</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
Returns the double (floating point) value of
|
|
<parameter>var</parameter>.
|
|
</simpara>
|
|
<para>
|
|
<parameter>Var</parameter> may be any scalar type. You cannot use
|
|
<function>doubleval</function> on arrays or objects.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
$var = '122.34343The';
|
|
$double_value_of_var = doubleval ($var);
|
|
print $double_value_of_var; // prints 122.34343
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<simpara>
|
|
See also <function>intval</function>,
|
|
<function>strval</function>, <function>settype</function> and
|
|
<link linkend="language.types.type-juggling">Type
|
|
juggling</link>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.empty">
|
|
<refnamediv>
|
|
<refname>empty</refname>
|
|
<refpurpose>Determine whether a variable is set</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>int <function>empty</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns false if <parameter>var</parameter> is set and has a
|
|
non-empty or non-zero value; true otherwise.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
$var = 0;
|
|
|
|
if (empty($var)) { // evaluates true
|
|
echo '$var is either 0 or not set at all';
|
|
}
|
|
|
|
if (!isset($var)) { // evaluates false
|
|
echo '$var is not set at all';
|
|
}
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<simpara>
|
|
Note that this is meaningless when used on anything which isn't a
|
|
variable; i.e. <command>empty (addslashes ($name))</command> has
|
|
no meaning since it would be checking whether something which
|
|
isn't a variable is a variable with a false value.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>isset</function> and
|
|
<function>unset</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.gettype">
|
|
<refnamediv>
|
|
<refname>gettype</refname>
|
|
<refpurpose>Get the type of a variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>string <function>gettype</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns the type of the PHP variable
|
|
<parameter>var</parameter>.
|
|
</para>
|
|
<para>
|
|
Possibles values for the returned string are:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>"boolean"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"integer"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"double"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"string"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"array"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"object"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"resource"</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"user function" (PHP 3 only, deprecated)</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>"unknown type"</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
<para>
|
|
For PHP 4, you should use <function>function_exists</function> and
|
|
<function>method_exists</function> to replace the prior usage of
|
|
<function>gettype</function> on a function.
|
|
</para>
|
|
<para>
|
|
See also <function>settype</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.intval">
|
|
<refnamediv>
|
|
<refname>intval</refname>
|
|
<refpurpose>Get integer value of a variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>int <function>intval</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
<paramdef>int
|
|
<parameter><optional>base</optional></parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
Returns the integer value of <parameter>var</parameter>,
|
|
using the specified base for the conversion (the default is
|
|
base 10).
|
|
</simpara>
|
|
<simpara>
|
|
<parameter>Var</parameter> may be any scalar type. You cannot use
|
|
<function>intval</function> on arrays or objects.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>doubleval</function>,
|
|
<function>strval</function>, <function>settype</function> and
|
|
<link linkend="language.types.type-juggling">Type
|
|
juggling</link>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-array">
|
|
<refnamediv>
|
|
<refname>is_array</refname>
|
|
<refpurpose>Finds whether a variable is an array</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_array</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if <parameter>var</parameter> is an array, false
|
|
otherwise.
|
|
</para>
|
|
<para>
|
|
See also <function>is_double</function>,
|
|
<function>is_float</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_real</function>,
|
|
<function>is_string</function>,
|
|
<function>is_long</function>, and
|
|
<function>is_object</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-bool">
|
|
<refnamediv>
|
|
<refname>is_bool</refname>
|
|
<refpurpose>
|
|
Finds out whether a variable is a boolean
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool
|
|
<function>is_bool</function>
|
|
</funcdef>
|
|
<paramdef>mixed
|
|
<parameter>var</parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if the <parameter>var</parameter> parameter is
|
|
a boolean.
|
|
</para>
|
|
<para>
|
|
See also <function>is_array</function>,
|
|
<function>is_double</function>,
|
|
<function>is_float</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_real</function>,
|
|
<function>is_string</function>,
|
|
<function>is_long</function>, and
|
|
<function>is_object</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-double">
|
|
<refnamediv>
|
|
<refname>is_double</refname>
|
|
<refpurpose>Finds whether a variable is a double</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_double</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if <parameter>var</parameter> is a double,
|
|
false otherwise.
|
|
</para>
|
|
<para>
|
|
See also <function>is_array</function>,
|
|
<function>is_bool</function>,
|
|
<function>is_float</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_real</function>,
|
|
<function>is_string</function>,
|
|
<function>is_long</function>, and
|
|
<function>is_object</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-float">
|
|
<refnamediv>
|
|
<refname>is_float</refname>
|
|
<refpurpose>Finds whether a variable is a float</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_float</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
This function is an alias for <function>is_double</function>.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>is_double</function>,
|
|
<function>is_bool</function>,
|
|
<function>is_real</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_string</function>,
|
|
<function>is_object</function>,
|
|
<function>is_array</function>, and
|
|
<function>is_long</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-int">
|
|
<refnamediv>
|
|
<refname>is_int</refname>
|
|
<refpurpose>Find whether a variable is an integer</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_int</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
This function is an alias for <function>is_long</function>.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>is_bool</function>,
|
|
<function>is_double</function>,
|
|
<function>is_float</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_string</function>,
|
|
<function>is_real</function>,
|
|
<function>is_object</function>,
|
|
<function>is_array</function>, and
|
|
<function>is_long</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-integer">
|
|
<refnamediv>
|
|
<refname>is_integer</refname>
|
|
<refpurpose>Find whether a variable is an integer</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_integer</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
This function is an alias for
|
|
<function>is_long</function>.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>is_bool</function>,
|
|
<function>is_double</function>,
|
|
<function>is_float</function>,
|
|
<function>is_int</function>,
|
|
<function>is_string</function>,
|
|
<function>is_real</function>,
|
|
<function>is_object</function>,
|
|
<function>is_array</function>, and
|
|
<function>is_long</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-long">
|
|
<refnamediv>
|
|
<refname>is_long</refname>
|
|
<refpurpose>Finds whether a variable is an integer</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_long</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if <parameter>var</parameter> is an integer (long),
|
|
false otherwise.
|
|
</para>
|
|
<para>
|
|
See also <function>is_bool</function>,
|
|
<function>is_double</function>,
|
|
<function>is_float</function>,
|
|
<function>is_int</function>,
|
|
<function>is_real</function>,
|
|
<function>is_string</function>,
|
|
<function>is_object</function>,
|
|
<function>is_array</function>, and
|
|
<function>is_integer</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-numeric">
|
|
<refnamediv>
|
|
<refname>is_numeric</refname>
|
|
<refpurpose>
|
|
Finds whether a variable is a number or a numeric string
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_numeric</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if <parameter>var</parameter> is a number or a
|
|
numeric string, false otherwise.
|
|
</para>
|
|
<para>
|
|
See also <function>is_bool</function>,
|
|
<function>is_double</function>,
|
|
<function>is_float</function>,
|
|
<function>is_int</function>,
|
|
<function>is_real</function>,
|
|
<function>is_string</function>,
|
|
<function>is_object</function>,
|
|
<function>is_array</function>, and
|
|
<function>is_integer</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-object">
|
|
<refnamediv>
|
|
<refname>is_object</refname>
|
|
<refpurpose>Finds whether a variable is an object</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_object</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if <parameter>var</parameter> is an object, false
|
|
otherwise.
|
|
</para>
|
|
<para>
|
|
See also <function>is_bool</function>,
|
|
<function>is_long</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_float</function>,
|
|
<function>is_double</function>,
|
|
<function>is_real</function>,
|
|
<function>is_string</function>, and
|
|
<function>is_array</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-real">
|
|
<refnamediv>
|
|
<refname>is_real</refname>
|
|
<refpurpose>Finds whether a variable is a real</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_real</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
This function is an alias for <function>is_double</function>.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>is_bool</function>,
|
|
<function>is_long</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_float</function>,
|
|
<function>is_double</function>,
|
|
<function>is_object</function>,
|
|
<function>is_string</function>, and
|
|
<function>is_array</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-resource">
|
|
<refnamediv>
|
|
<refname>is_resource</refname>
|
|
<refpurpose>
|
|
Finds whether a variable is a resource
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool
|
|
<function>is_resource</function>
|
|
</funcdef>
|
|
<paramdef>mixed
|
|
<parameter>var</parameter>
|
|
</paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
<function>is_resource</function> returns true if the variable
|
|
given by the <parameter>var</parameter> parameter is a resource,
|
|
otherwise it returns false.
|
|
</para>
|
|
<para>
|
|
Resources are things like file or database result handles that
|
|
are allocated and freed by internal PHP functions and that may
|
|
need some cleanup when they are no longer in use but haven't been
|
|
freed by user code.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.is-string">
|
|
<refnamediv>
|
|
<refname>is_string</refname>
|
|
<refpurpose>Finds whether a variable is a string</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>is_string</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns true if <parameter>var</parameter> is a string,
|
|
false otherwise.
|
|
</para>
|
|
<para>
|
|
See also <function>is_bool</function>,
|
|
<function>is_long</function>,
|
|
<function>is_int</function>,
|
|
<function>is_integer</function>,
|
|
<function>is_float</function>,
|
|
<function>is_double</function>,
|
|
<function>is_real</function>,
|
|
<function>is_object</function>, and
|
|
<function>is_array</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.isset">
|
|
<refnamediv>
|
|
<refname>isset</refname>
|
|
<refpurpose>Determine whether a variable is set</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>int <function>isset</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
Returns true if <parameter>var</parameter> exists;
|
|
false otherwise.
|
|
</simpara>
|
|
<para>
|
|
If a variable has been unset with <function>unset</function>,
|
|
it will no longer be <function>isset</function>.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
$a = "test";
|
|
echo isset ($a); // true
|
|
unset ($a);
|
|
echo isset ($a); // false
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<simpara>
|
|
See also <function>empty</function> and
|
|
<function>unset</function>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.print-r">
|
|
<refnamediv>
|
|
<refname>print_r</refname>
|
|
<refpurpose>
|
|
Prints human-readable information about a variable
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void <function>print_r</function></funcdef>
|
|
<paramdef>mixed <parameter>expression</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
This function displays information about the values of variables
|
|
in a way that's readable by humans. If given a string, integer
|
|
or double, the value itself will be printed. If given an array,
|
|
values will be presented in a format that shows keys and
|
|
elements. Similar notation is used for objects.
|
|
</simpara>
|
|
<simpara>
|
|
Compare <function>print_r</function> to
|
|
<function>var_dump</function>.
|
|
</simpara>
|
|
<para>
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<?php
|
|
$a = array (1, 2, array ("a", "b", "c"));
|
|
print_r ($a);
|
|
?>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
This function will continue forever if given an array or object
|
|
that contains a direct or indirect reference to itself or that
|
|
contains an array or object on a deeper level that does so.
|
|
This is especially true for <literal>print_r($GLOBALS)</literal>,
|
|
as <literal>$GLOBALS</literal> is itself a global variable and
|
|
contains a reference to itself as such.
|
|
</para>
|
|
</warning>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.serialize">
|
|
<refnamediv>
|
|
<refname>serialize</refname>
|
|
<refpurpose>
|
|
Generates a storable representation of a value
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>string <function>serialize</function></funcdef>
|
|
<paramdef>mixed <parameter>value</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
<function>Serialize</function> returns a string containing a
|
|
byte-stream representation of <parameter>value</parameter> that
|
|
can be stored anywhere.
|
|
</simpara>
|
|
<simpara>
|
|
This is useful for storing or passing PHP values around without
|
|
losing their type and structure.
|
|
</simpara>
|
|
<simpara>
|
|
To make the serialized string into a PHP value again, use
|
|
<function>unserialize</function>. <function>Serialize</function>
|
|
handles the types <type>integer</type>, <type>double</type>,
|
|
<type>string</type>, <type>array</type> (multidimensional) and
|
|
<type>object</type> (object properties will be serialized, but
|
|
methods are lost).
|
|
</simpara>
|
|
<para>
|
|
<example>
|
|
<title><function>Serialize</function> example</title>
|
|
<programlisting role="php">
|
|
// $session_data contains a multi-dimensional array with session
|
|
// information for the current user. We use serialize() to store
|
|
// it in a database at the end of the request.
|
|
|
|
$conn = odbc_connect ("webdb", "php", "chicken");
|
|
$stmt = odbc_prepare ($conn,
|
|
"UPDATE sessions SET data = ? WHERE id = ?");
|
|
$sqldata = array (serialize($session_data), $PHP_AUTH_USER);
|
|
if (!odbc_execute ($stmt, &$sqldata)) {
|
|
$stmt = odbc_prepare($conn,
|
|
"INSERT INTO sessions (id, data) VALUES(?, ?)");
|
|
if (!odbc_execute($stmt, &$sqldata)) {
|
|
/* Something went wrong. Bitch, whine and moan. */
|
|
}
|
|
}
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.settype">
|
|
<refnamediv>
|
|
<refname>settype</refname>
|
|
<refpurpose>Set the type of a variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>int <function>settype</function></funcdef>
|
|
<paramdef>string <parameter>var</parameter></paramdef>
|
|
<paramdef>string <parameter>type</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Set the type of variable <parameter>var</parameter> to
|
|
<parameter>type</parameter>.
|
|
</para>
|
|
<para>
|
|
Possibles values of <parameter>type</parameter> are:
|
|
<itemizedlist>
|
|
<listitem><simpara>"integer"</simpara></listitem>
|
|
<listitem><simpara>"double"</simpara></listitem>
|
|
<listitem><simpara>"string"</simpara></listitem>
|
|
<listitem><simpara>"array"</simpara></listitem>
|
|
<listitem><simpara>"object"</simpara></listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
<para>
|
|
Returns true if successful; otherwise returns false.
|
|
</para>
|
|
<para>
|
|
See also <function>gettype</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.strval">
|
|
<refnamediv>
|
|
<refname>strval</refname>
|
|
<refpurpose>Get string value of a variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>string <function>strval</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
Returns the string value of <parameter>var</parameter>.
|
|
</simpara>
|
|
<simpara>
|
|
<parameter>var</parameter> may be any scalar type. You cannot use
|
|
<function>strval</function> on arrays or objects.
|
|
</simpara>
|
|
<simpara>
|
|
See also <function>doubleval</function>,
|
|
<function>intval</function>, <function>settype</function> and
|
|
<link linkend="language.types.type-juggling">Type
|
|
juggling</link>.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.unserialize">
|
|
<refnamediv>
|
|
<refname>unserialize</refname>
|
|
<refpurpose>
|
|
Creates a PHP value from a stored representation
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>mixed <function>unserialize</function></funcdef>
|
|
<paramdef>string <parameter>str</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
<function>unserialize</function> takes a single serialized
|
|
variable (see <function>serialize</function>) and converts it
|
|
back into a PHP value. The converted value is returned, and can
|
|
be an <type>integer</type>, <type>double</type>,
|
|
<type>string</type>, <type>array</type> or <type>object</type>.
|
|
If an object was serialized, its methods are not preserved in the
|
|
returned value.
|
|
</simpara>
|
|
<para>
|
|
<example>
|
|
<title><function>Unserialize</function> example</title>
|
|
<programlisting role="php">
|
|
// Here, we use unserialize() to load session data from a database
|
|
// into $session_data. This example complements the one described
|
|
// with <function>serialize</function>.
|
|
|
|
$conn = odbc_connect ("webdb", "php", "chicken");
|
|
$stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?");
|
|
$sqldata = array ($PHP_AUTH_USER);
|
|
if (!odbc_execute ($stmt, &$sqldata) || !odbc_fetch_into ($stmt, &$tmp)) {
|
|
// if the execute or fetch fails, initialize to empty array
|
|
$session_data = array();
|
|
} else {
|
|
// we should now have the serialized data in $tmp[0].
|
|
$session_data = unserialize ($tmp[0]);
|
|
if (!is_array ($session_data)) {
|
|
// something went wrong, initialize to empty array
|
|
$session_data = array();
|
|
}
|
|
}
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.unset">
|
|
<refnamediv>
|
|
<refname>unset</refname>
|
|
<refpurpose>Unset a given variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>int <function>unset</function></funcdef>
|
|
<paramdef>mixed <parameter>var</parameter></paramdef>
|
|
<paramdef>mixed <parameter><optional>var</optional></parameter></paramdef>
|
|
<paramdef><parameter><optional>...</optional></parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
<function>unset</function> destroys the specified variables and
|
|
returns true.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>Unset</function> example</title>
|
|
<programlisting role="php">
|
|
// destroy a single variable
|
|
unset ($foo);
|
|
|
|
// destroy a single element of an array
|
|
unset ($bar['quux']);
|
|
|
|
// destroy more than one variable
|
|
unset ($foo1, $foo2, $foo3);
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
The behavior of <function>unset</function> inside of a function
|
|
can vary depending on what type of variable you are attempting to
|
|
destroy.
|
|
</para>
|
|
<para>
|
|
If a globalized variable is <function>unset</function> inside of
|
|
a function, only the local variable is destroyed. The variable
|
|
in the calling environment will retain the same value as before
|
|
<function>unset</function> was called.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
function destroy_foo() {
|
|
global $foo;
|
|
unset($foo);
|
|
}
|
|
|
|
$foo = 'bar';
|
|
destroy_foo();
|
|
echo $foo;
|
|
</programlisting>
|
|
</informalexample>
|
|
The above example would output:
|
|
<informalexample>
|
|
<programlisting>
|
|
bar
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
If a variable that is PASSED BY REFERENCE is
|
|
<function>unset</function> inside of a function, only the local
|
|
variable is destroyed. The variable in the calling environment
|
|
will retain the same value as before <function>unset</function>
|
|
was called.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
function foo(&$bar) {
|
|
unset($bar);
|
|
$bar = "blah";
|
|
}
|
|
|
|
$bar = 'something';
|
|
echo "$bar\n";
|
|
|
|
foo($bar);
|
|
echo "$bar\n";
|
|
</programlisting>
|
|
</informalexample>
|
|
The above example would output:
|
|
<informalexample>
|
|
<programlisting>
|
|
something
|
|
something
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
If a static variable is <function>unset</function> inside of a
|
|
function, <function>unset</function> unsets the reference to the
|
|
static variable, rather than the static variable itself.
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
function foo() {
|
|
static $a;
|
|
$a++;
|
|
echo "$a\n";
|
|
|
|
unset($a);
|
|
}
|
|
|
|
foo();
|
|
foo();
|
|
foo();
|
|
</programlisting>
|
|
</informalexample>
|
|
The above example would output:
|
|
<informalexample>
|
|
<programlisting>
|
|
1
|
|
2
|
|
3
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
If you would like to <function>unset</function> a global variable inside of a function, you can use the <parameter>$GLOBALS</parameter> array to do so:
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
function foo() {
|
|
unset($GLOBALS['bar']);
|
|
}
|
|
|
|
$bar = "something";
|
|
foo();
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
See also <function>isset</function> and
|
|
<function>empty</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.var-dump">
|
|
<refnamediv>
|
|
<refname>var_dump</refname>
|
|
<refpurpose>Dumps information about a variable</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void <function>var_dump</function></funcdef>
|
|
<paramdef>mixed <parameter>expression</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<simpara>
|
|
This function returns structured information about an expression
|
|
that includes its type and value. Arrays are explored
|
|
recursively with values indented to show structure.
|
|
</simpara>
|
|
<simpara>
|
|
Compare <function>var_dump</function> to
|
|
<function>print_r</function>.
|
|
</simpara>
|
|
<para>
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<pre>
|
|
<?php
|
|
$a = array (1, 2, array ("a", "b", "c"));
|
|
var_dump ($a);
|
|
?>
|
|
</pre>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
</reference>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
-->
|