<HTML ><HEAD ><TITLE >How to read a function definition (prototype)</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="About the manual" HREF="about.html"><LINK REL="PREVIOUS" TITLE="About user notes" HREF="about.notes.html"><LINK REL="NEXT" TITLE="PHP versions documented in this manual" HREF="about.phpversions.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="about.notes.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Appendix K. About the manual</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="about.phpversions.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="about.prototypes" ></A >How to read a function definition (prototype)</H1 ><P > Each function is documented for quick reference, knowing how to read and understand the manual will make using PHP much easier. Rather than relying on examples or cut/paste, you want to know how to read function definitions (prototypes). Let's begin: </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Prerequisite: Basic understanding of <A HREF="language.types.html" >types</A >: </B > Although PHP is a loosly typed language, it's important to have a basic understanding of <A HREF="language.types.html" >types</A > as they have important meaning. </P ></BLOCKQUOTE ></DIV ><P > Function definitions tell us what type of value is <A HREF="functions.returning-values.html" >returned</A >, let's use the definition for <A HREF="function.strlen.html" ><B CLASS="function" >strlen()</B ></A > as our first example: </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" >strlen (PHP 3, PHP 4 >= 4.0.0) strlen -- Get string length Description int strlen ( string str ) Returns the length of string.</PRE ></TD ></TR ></TABLE > </P ><P > <DIV CLASS="table" ><A NAME="AEN111260" ></A ><P ><B >Table K-1. Explanation of a function definition</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Part</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" > strlen </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > The function name. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" > (PHP 3, PHP 4 >= 4.0.0) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > strlen() has been around in both all of PHP 3 and PHP 4 </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" > int </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Type of value this function returns, which is an <A HREF="language.types.integer.html" >integer</A > (i.e. The length of a string is measured in numbers). </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" > ( string str ) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > The first (and in this case the only) parameter/argument for the function strlen() is named <TT CLASS="parameter" ><I >str</I ></TT >, and it's a <A HREF="language.types.string.html" >string</A >. </TD ></TR ></TBODY ></TABLE ></DIV > </P ><P > We could rewrite the above function definition in a generic way: </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" >returned type function name ( parameter type parameter name )</PRE ></TD ></TR ></TABLE > </P ><P > Many functions take on multiple parameters, such as <A HREF="function.in-array.html" ><B CLASS="function" >in_array()</B ></A >. It's prototype is as follows: </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="html" >bool in_array ( mixed needle, array haystack [, bool strict])</PRE ></TD ></TR ></TABLE > </P ><P > What does this mean? in_array() returns a <A HREF="language.types.boolean.html" >boolean</A > value, <TT CLASS="constant" ><B >TRUE</B ></TT > on success (the <TT CLASS="parameter" ><I >needle</I ></TT > was found in the <TT CLASS="parameter" ><I >haystack</I ></TT >) or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure (the <TT CLASS="parameter" ><I >needle</I ></TT > was not found in the <TT CLASS="parameter" ><I >haystack</I ></TT >). The first parameter is named <TT CLASS="parameter" ><I >needle</I ></TT > and it can be many different <A HREF="language.types.html" >types</A >, so we call it "<SPAN CLASS="emphasis" ><I CLASS="emphasis" >mixed</I ></SPAN >". This mixed <TT CLASS="parameter" ><I >needle</I ></TT > (what we're looking for) can either be a scalar value (string, integer, or <A HREF="language.types.float.html" >float</A >), or an <A HREF="language.types.array.html" >array</A >. <TT CLASS="parameter" ><I >haystack</I ></TT > (the array we're searching in) is the second parameter. The third <SPAN CLASS="emphasis" ><I CLASS="emphasis" >optional</I ></SPAN > parameter is named <TT CLASS="parameter" ><I >strict</I ></TT >. All optional parameters are seen in <SPAN CLASS="emphasis" ><I CLASS="emphasis" >[</I ></SPAN > brackets <SPAN CLASS="emphasis" ><I CLASS="emphasis" >]</I ></SPAN >. The manual states that the <TT CLASS="parameter" ><I >strict</I ></TT > parameter defaults to boolean <TT CLASS="constant" ><B >FALSE</B ></TT >. See the manual page on each function for details on how they work. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="about.notes.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="about.phpversions.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >About user notes</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="about.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >PHP versions documented in this manual</TD ></TR ></TABLE ></DIV ></BODY ></HTML >