page1.html
page2.html page3.html page4.html The foreword The authors and Participants I. Beginning to job 1. Introduction 2. Brief management(manual) II. Installation and adjustment 3. General Installation Considerations 4. Installation on Unix systems 5. Installation on Mac OS X 6. Installation on Windows systems 7. Installation of PECL extensions 8. Problems? 9. Runtime Configuration III. The directory of language 10. Basis of syntax 11. Types 12. Variable 13. Constant 14. Expression 15. Operators 16. Control Structures 17. Function 18. Classes and Objects (PHP 4) 19. Classes and objects (PHP 5) 20. Exceptions 21. Reference. Explanations IV. Safety 22. Introduction 23. General(common) reasonings 24. If PHP is established as CGI 25. If PHP is established as the module Apache 26. Safety of file system 27. Safety of databases 28. Error message 29. Use global variable (Register_Globals) 30. Data entered by the user 31. Magic Quotes 32. Concealment PHP 33. Necessity обновлений V. Distinctive features 34. HTTP-Аутентификация in PHP 35. Cookies 36. Sessions 37. Job with XForms 38. Loading files on a server 39. Job with the removed files 40. Job with connections 41. Constant connections with databases 42. Protected mode 43. Use PHP in a command line VI. The directory of functions I.. NET Functions II. Advanced PHP debugger III. Alternative PHP Cache IV. Functions for job with a server Apache V. Function for job with files VI. Aspell functions [deprecated] VII. BCMath Arbitrary Precision Mathematics Functions VIII. Functions of compression Bzip2 IX. Calendar Functions X. CCVS API Functions [deprecated] XI. Functions of definition such as symbols XII. Functions of job with Classes / objects XIII. Classkit Functions XIV. ClibPDF Functions XV. COM and .Net (Windows) XVI. Crack Functions XVII. Credit Mutuel CyberMUT functions XVIII. Functions CURL, Client URL Library XIX. Cybercash Payment Functions XX. Cyrus IMAP administration Functions XXI. Database (dbm-style) Abstraction Layer Functions XXII. Functions for job with date and time XXIII. DB ++ Functions XXIV. dBase Functions XXV. DBM Functions [deprecated] XXVI. dbx Functions XXVII. Direct IO Functions XXVIII. Functions for job with the catalogues XXIX. DOM Functions XXX. DOM XML Functions XXXI. Error Handling and Logging Functions XXXII. Exif Functions XXXIII. File Alteration Monitor Functions XXXIV. filePro Functions XXXV. Functions for job with file system XXXVI. Firebird/InterBase Functions XXXVII. Firebird/Interbase Functions (PDO_FIREBIRD) XXXVIII. Forms Data Format Functions XXXIX. FriBiDi Functions XL. FrontBase Functions XLI. Functions for job with FTP XLII. Management of functions XLIII. Gettext XLIV. GMP Functions XLV. GNU Readline XLVI. GNU Recode Functions XLVII. Functions of the protocol HTTP XLVIII. Hyperwave API Functions XLIX. Hyperwave Functions L. IBM DB2, Cloudscape and Apache Derby Functions LI. ICAP Functions [deprecated] LII. Functions iconv LIII. ID3 Functions LIV. IIS Administration Functions LV. Image Functions LVI. IMAP, POP3 and NNTP Functions LVII. Informix Functions LVIII. Ingres II Functions LIX. IRC Gateway Functions LX. KADM5 LXI. LDAP Functions LXII. libxml Functions LXIII. Lotus Notes Functions LXIV. LZF Functions LXV. Mail Functions LXVI. mailparse Functions LXVII. Mathematical functions LXVIII. MaxDB PHP Extension LXIX. MCAL Functions LXX. Mcrypt Encryption Functions LXXI. MCVE Payment Functions LXXII. Memcache Functions LXXIII. Mhash Functions LXXIV. Microsoft SQL Server and Sybase Functions (PDO_DBLIB) LXXV. Microsoft SQL Server Functions LXXVI. Mimetype Functions LXXVII. Ming functions for Flash LXXVIII. Miscellaneous Functions LXXIX. mnoGoSearch Functions LXXX. Mohawk Software Session Handler Functions LXXXI. mSQL Functions LXXXII. Multibyte String Functions LXXXIII. muscat Functions LXXXIV. Functions СУБД MySQL LXXXV. MySQL Functions (PDO_MYSQL) LXXXVI. MySQL Improved Extension LXXXVII. Ncurses Terminal Screen Control Functions LXXXVIII. Network Functions LXXXIX. Net_Gopher XC. NSAPI-specific Functions XCI. Object Aggregation/Composition Functions XCII. Object property and method call overloading XCIII. ODBC and DB2 functions (PDO_ODBC) XCIV. ODBC Functions (Unified) XCV. oggvorbis XCVI. OpenAL Audio Bindings XCVII. OpenSSL Functions XCVIII. Functions for job with Oracle XCIX. Oracle Functions (PDO_OCI) C. Oracle Functions [deprecated] CI. Output Control Functions CII. Ovrimos SQL Functions CIII. Paradox File Access CIV. Parsekit Functions CV. PDF functions CVI. PDO Functions CVII. PHP / Java Integration CVIII. PHP bytecode Compiler CIX. PHP Options*Information CX. POSIX Functions CXI. PostgreSQL Functions CXII. PostgreSQL Functions (PDO_PGSQL) CXIII. PostgreSQL Session Save Handler CXIV. PostScript document creation CXV. Printer Functions CXVI. Process Control Functions CXVII. Program Execution Functions CXVIII. Pspell Functions CXIX. qtdom Functions CXX. Radius CXXI. Rar of function CXXII. Functions for job with regular expressions (Perl-compatible) CXXIII. Regular Expression Functions (POSIX Extended) CXXIV. runkit Functions CXXV. Satellite CORBA client extension [deprecated] CXXVI. SDO Functions CXXVII. SDO Relational Data Access Service Functions CXXVIII. SDO XML Data Access Service Functions CXXIX. Secure Shell2 Functions CXXX. Semaphore, Shared Memory and IPC Functions CXXXI. SESAM Database Functions CXXXII. Session Handling Functions CXXXIII. Shared Memory Functions CXXXIV. Shockwave Flash Functions CXXXV. SimpleXML functions CXXXVI. SNMP Functions CXXXVII. SOAP Functions CXXXVIII. Socket Functions CXXXIX. SQLite CXL. SQLite Functions (PDO_SQLITE) CXLI. Standard PHP Library (SPL) Functions CXLII. Stream Functions CXLIII. Functions of processing of lines CXLIV. Sybase Functions CXLV. TCP Wrappers Functions CXLVI. Tidy Functions CXLVII. Tokenizer Functions CXLVIII. Unicode Functions CXLIX. URL Functions CL. Variable Handling Functions CLI. Verisign Payflow Pro Functions CLII. vpopmail Functions CLIII. W32api Functions CLIV. WDDX Functions CLV. win32service Functions CLVI. xattr Functions CLVII. xdiff Functions CLVIII. XML Parser Functions CLIX. XML-RPC Functions CLX. XMLReader functions CLXI. XSL functions CLXII. XSLT Functions CLXIII. YAZ Functions CLXIV. YP/NIS Functions CLXV. Zip File Functions (Read Only Access) CLXVI. Functions of compression Zlib VII. PHP and Zend Engine Internals 44. Streams API for PHP Extension Authors 45. Zend API: Hacking the Core of PHP 46. Extending PHP 3 VIII. ЧАВО: OFTEN set Questions and Answers on them 47. General(common) Information 48. Lists of dispatch 49. Reception PHP 50. Questions on Databases 51. Installation 52. Problem of Assembly 53. Use PHP 54. PHP and HTML 55. PHP and COM 56. PHP and other languages 57. Transition from PHP 2 in PHP 3 58. Transition from PHP 3 in PHP 4 59. Transition from PHP 4 in PHP 5 60. Different questions IX. The applications A. History PHP and adjacent projects B. Migration with PHP 4 on PHP 5 C. Migrating from PHP 3 to PHP 4 D. Migrating from PHP/FI 2 to PHP 3 E. Debugging PHP F. Configure options G. Instruction php.ini H. Extension Categorization I. List of pseudonyms of functions J. List of Reserved Words K. List of Resource Types L. List of Supported Protocols/Wrappers M. List of accessible filters N. List of the supported transport protocols O. Table of comparison of types in PHP P. List of Parser Tokens Q. About this management(manual) R. Open Publication License S. List of functions T. That is absent in this management(manual) X. Management(manual) in a format HTML Help 61. About This Edition 62. Using PHP Manual CHM Edition 63. The Full Text Search 64. Specialities of this Edition 65. Integrating the PHP Manual 66. Skin development 67. CHM Edition Credits The chapter 1. Introduction The contents What such PHP? Opportunities PHP What such PHP? PHP (рекурсивный акроним of a word collocation " PHP: Hypertext Preprocessor ") is a widely used programming language of general(common) purpose(appointment) with an open initial code. PHP is designed specially for conducting Web-development and can take root into a HTML-code. The simple answer, but what he can mean? An example: Example 1-1. An example of programming on PHP an Example Pay attention to difference it скрипта from скриптов, written on other languages, for example, on Perl or C - instead of creating the program, which is engaged in formation of a HTML-code and contains uncountable set of the commands,(teams,) intended for it, you create a HTML-code with the several introduced commands(teams) PHP (in the given case intended for a conclusion of the text). The code PHP is separated special initial and final тегами, which allow the processor PHP to define(determine) a beginning and end of a site of a HTML-code containing PHP-скрипт. Significant difference PHP from any of a code which is carried out on the party of the client, for example, JavaScript, is that PHP-скрипты are carried out on a server. If with you on a server was placed скрипт, similar above-stated, the client would receive only result of performance скрипта, and he could not find out, which code is carried out. You even can сконфигурировать the server so that the HTML-files were processed by the processor PHP, so the clients can not learn(find out) at all, whether they receive a usual HTML-file or result of performance скрипта. PHP is extremely simple for development, but at the same time is capable to satisfy inquiries of the professional programmers. After you for the first time have heard about PHP, and have opened this management(manual), within several hours you already can create simple PHP-скрипты. Though PHP, mainly, is intended for job in environment(Wednesday) of web-servers, the area of his(its) application is not limited only to it. Read further and do not pass(miss) the chapter of an Opportunity PHP or, begin directly from an Introduction management(manual), if you the extremely веб-programming interests Management(manual) on PHP Пред. The chapter 1. Introduction a Trace. Opportunities PHP PHP all can. Mainly, the area of application PHP is focused on a spelling скриптов, working on the party of a server; thus, PHP is capable to carry out вс ё that any other program CGI, for example carries out, to process of the given forms, to generate dynamic pages or to send and to accept cookies. But PHP is capable to carry out and set of other tasks. There are three basic areas, where is used PHP. Creation скриптов for performance on the party of a server. PHP is most widely used thus. Everything, that is required to you, it парсер PHP (as the program CGI or серверного of the module), веб-server and броузер. That you could look through results of performance PHP-скриптов in броузере, to you the working веб-server and established PHP is necessary. In case you simply experiment, you quite can use the home computer instead of a server. Behind more particularies Advice(councils) on installation addresses to the chapter. Creation скриптов for performance in a command line. You can create PHP-скрипт, capable to be started without dependence from вебсервера and броузера. Everything, that is required to you - парсер PHP. Such way of use PHP ideally approaches for скриптов, which should be carried out regularly, for example, with the help cron (on platforms *nix or Linux) or with the help of the scheduler of tasks (Task Scheduler) on platforms Windows. These скрипты also can be used in tasks of simple processing of the texts. Behind the additional information address to the chapter Use PHP in environment(Wednesday) of a command line. Creation of the window applications which are carried out on the party of the client. Probably, PHP is not the best language for creation of the similar applications, but, if you very well know PHP and would like to use his(its) some opportunities in the clients - applications, you can use PHP-GTK for creation of such applications. In a similar way you can create and кросс-платформенные of the application. PHP-GTK is expansion PHP and is not delivered together with the distribution kit PHP. If you are interested, visit a site PHP-GTK. PHP is accessible to the majority of operational systems, switching Linux, many updatings Unix (such, as HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and many others. (is completely exact, that there is a version PHP for OS/2. The truth, as far as appropriate to present realities - Прим.перев is not known.) Also in PHP the support of the majority modern вебсерверов, such, as Apache, Microsoft Internet Information Server, Personal Web Server, servers Netscape and iPlanet, server Oreilly Website Pro, Caudium, Xitami, OmniHTTPd and many others is switched on. For the majority of servers PHP is delivered as the module, for others, supporting the standard CGI, PHP can function as the processor CGI. Thus, choosing PHP, you receive freedom of a choice of operational system and вебсервера. Besides you have a choice between use of procedural or объектно-guided programming or their combination. In spite of the fact that PHP 4 (the current stable version) supports not all features ООП, many libraries of a code and large applications (including library PEAR) are written only with use ООП. PHP 5 corrects some of weakness inherent realizations ООП in PHP 4 and gives to the developer целосную объектную model. PHP is capable not only to give out HTML. The opportunities PHP include formation of the images, files PDF and even of rollers Flash (with use libswf and Ming), created " on summer ". PHP also is capable to give out any text given, such, as XHTML and other XML-file.s PHP is capable to carry out automatic generation of such files and to save them in file system of your server instead of giving back to the client, organizing, thus, кеш of the dynamic contents located on the party of a server. One of significant advantages PHP is the support of a wide circle of databases. The creation скрипта, using databases, - is incredibly simple. Now PHP supports the following databases: Adabas D InterBase PostgreSQL dBase FrontBase SQLite Empress mSQL Solid FilePro (only reading) Direct MS-SQL Sybase Hyperwave MySQL Velocis IBM DB2 ODBC Unix dbm Informix Oracle (OCI7 and OCI8) Ingres Ovrimos Also in PHP the support DBX for job at an abstract level is switched on, so you can work with any database using DBX. Besides PHP supports ODBC (Open Database Connection standard), thus, you can work with any database supporting this всемирно the recognized standard. PHP also supports "dialogue" with other services with use of such protocols, as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on platforms Windows) and many others. Besides you receive an opportunity to work with network сокетами "directly". PHP supports the standard of an exchange of complex(difficult) structures of the data WDDX. Paying attention on it is necessary to mention interaction between various languages, support of objects Java and opportunity of their use as objects PHP. For access to the removed objects you can use expansion CORBA. PHP includes means of processing of the text information, since regular expressions Perl or POSIX Extended and finishing парсером of the documents XML. For парсинга XML in PHP 4 the standards SAX and DOM are used. For transformation of the documents XML you can use expansion XSLT. In PHP 5 processings of the XML-documents стандартизирована also occur on the basis of library libxml2. Two new expansions for job with XML also are added: SimpleXML and XMLReader. Using PHP in the field of electronic commerce, you pay attention to function of realization of payments Cybercash, CyberMUT, VeriSign Payflow Pro and CCVS. Last under the order, but not on meaning(importance), is the support of many other expansions, such, as functions of the search machine mnoGoSearch, function IRC Gateway, function for job with the compressed files (gzip, bz2), function of calendar calculations, function of translation... As you see, this page will not suffice to list everything, that can offer you PHP. Read the following chapter, Installation PHP and address to the chapter the Directory on functions behind more particularies on the listed above expansions. Пред. Began a Trace. Introduction a Level an above Brief management(manual) The first page on PHP Create a file with a name hello.php in the root catalogue of your documents of a Web-server and write down in him(it) the following: Example 2-1. First скрипт on PHP: hello.php Is tested PHP ";? > This program will deduce(remove) the following: Is tested PHP Hi!

Let's notice, that similarity with скриптами on CGI no. The file not to be obliged by feasible or marked any other image. It is a simply usual file HTML, in which there is a set special тегов, doing(making) it is a lot of interesting. This program is extremely simple, and for creation of a so simple page even it is unessential to use PHP. All that she does(makes) is deduces " Hi! With use of function PHP echo (). If at you this example does not display anything or deduces a window of loading, or if you see all this file in a text kind, it is rather probable, that your Web-server has no support PHP. Ask your manager of a server to switch on such support. Offer him the instruction on installation - section "Installation" of the given documentation. If you want to develop скрипты on PHP at home, to you in section necessary files. The houses can be developed скрипты with use of any operational system, but you need to establish the appropriate Web-server. The purpose of an example - to show a format special тегов PHP. In this example we used . Thus it is possible as much as necessary time to pass to a code PHP in a file HTML. Pair of words about the text editors: There is a set of the text editors and integrated environments(Wednesdays) of development (IDE), in which you can create and edit files PHP. The list of some editors contains in section " the List of the editors PHP ". If you want to recommend any editor, visit the given page and ask to add the given editor in the list. Pair of words about word-processors: the word-processors (StarOffice Writer, Microsoft Word, Abiword etc.) in most cases do not approach for editing files PHP. If you use a word-processor for creation скриптов on PHP, you should be sure, that save a file, as ONLY TEXT. Otherwise PHP can not process and execute your program. Pair of words about "Notebook" Windows: At a spelling скриптов PHP with use of built - in "Notebook" Windows it is necessary to save files with expansion .php. "Notebook" automatically adds expansion .txt. For detour of this problem there are some methods. It is possible to place the name of a file in inverted commas (example: "hello.php"). Besides it is possible to choose " All files " instead of " the Text documents " from ниспадающего of the list with types of files in a window of preservation. After that it is possible to enter a name of a file without inverted commas. Job with the forms One of mainest advantages PHP -, how he works with the forms HTML. Here basic is that each element of the form becomes automatically accessible to your programs on PHP. For the detailed information on use of the forms in PHP read section " Variable of external sources ". An example of the form HTML: Example 2-6. The elementary form HTML < form action = "action.php" method = "POST" > Your name: < input type = "text" name = "name" / > Your age: < input type = "text" name = "age" / > < input type = "submit" > In this form there is nothing especial. It is the usual form HTML without any special тегов. When the user will fill in the form and will press the button of sending, the page action.php will be called. In this file can be something like: Example 2-7. We deduce(remove) given of our forms Hello, . To you of years. Example of a conclusion of the given program: Hello, Сергей. To you 30 years. The principle of job of the given code is simple and be clear. Variable The $ _POST ["name"] and $ _POST ["age"] automatically are established for you by means PHP. Earlier we used variable $ _SERVER, here we precisely also use superglobal variable $ _POST, which contains all POST-given. Let's notice, that a method of sending of our form - POST. If we used a method GET, the information of our form would be in superglobal variable $ _GET. Also it is possible to use variable $ _REQUEST, if the source of the data has no meaning(importance). This variable contains a mix of the data GET, POST, COOKIE and FILE. Also we advise to look at the description of function import_request_variables (). Use of the old programs with the new versions PHP Now PHP is popular language of the scripts (скриптов). Becomes ever more and more distributed slices of a code, which you can use in скриптах. In most cases developers PHP tried to save compatibility with the previous versions so, that a code written for older version will be ideal to work and with the new versions of language without any changes. However happens so, that the changes all the same are necessary. There are two important changes, which influence the old programs: The announcement of files $HTTP_ * _ VARS out-of-date. These files required(demanded) глобализации in functions and procedures. The new superglobal files were entered, since PHP 4.1.0. It: $ _GET, $ _POST, $ _COOKIE, $ _SERVER, $ _ENV, $ _REQUEST, and $ _SESSION. Older files $HTTP_ * _ VARS, such, as $HTTP_POST_VARS, exist from times PHP 3 and, probably, will still long exist for preservation of compatibility. External variable any more глобализуются by default. In other words, the instruction register_globals in php.ini by default is switched - off ("off"), since PHP 4.2.0. A recommended method of access to such variable - superglobal files described above. Older programs, book and the managements(manual) can consider(count), that the given instruction is switched on ("on"). For example, variable $id can act from a line URL http: // www.example.com/foo.php? id=42. When the specified instruction is switched off, $id is accessible only as $ _GET ['id']. For the additional information concerning to changes connected with variable, look section " Predetermined variable " and reference of this unit. The chapter 10. Bases of syntax The contents Insert in HTML Division of the instructions Comment Insert in HTML When PHP processes a file, he simply passes his(its) text, one of special тегов yet will not meet which informs him necessity to begin interpretation of the text as code PHP. Then he carries out all found code up to closing тега, speaking to the interpreter, that further again there is simply text. This mechanism allows you to introduce a PHP-code in HTML - all outside тегов PHP remains constant, whereas inside - is interpreted as a code. There are four sets тегов, which can be used for a designation of a PHP-code. From them only two ( and < script language = "php" >... < /script >) are always accessible; others can be switched on or are switched off in a configuration file php.ini. Though short теги and теги in style ASP they can be convenient, not so переносимы, as the long versions. Besides if you intend to insert a PHP-code in XML or XHTML to correspond(meet) XML, you should use the form . Теги, supported PHP: Example 10-1. Ways of an insert in HTML 1. 2. It is a synonym for " " 3. < script language = "php" > echo (" some editors (for example, FrontPage) not Like the instructions of processing "); 4. < of % echo (" you can on a choice use теги in style ASP "); % > < % = $variable; * Is a synonym for " < of % echo... " Of % > The first way, , most preferable, as he allows to use PHP in a code appropriate to rules XML, such as XHTML. The second way is not always accessible. Short теги are accessible only when they are switched on. It can be made, using function short_tags () (only in PHP 3), having switched on installation short_open_tag in a configuration file PHP, or скомпилировав PHP with parameter - enable-short-tags for configure. Even if it is switched on by default in php.ini-dist, use short тегов is not recommended. The fourth way is accessible only if теги in style ASP were switched on, using configuration installation asp_tags. The remark: the support тегов in style ASP was added in the version 3.0.4. The remark: It is necessary to avoid use short тегов by development of the applications or libraries intended for distribution or accommodation on PHP-servers, not taking place under your control, as short теги can not be supported on a target server. For creation переносимого, compatible code, do not use short теги. Closing тег of the block of a PHP-code includes at once translation, following it,(him,) of a line, if he is present. Besides closing тег automatically means a point from a point; you do not need to finish last line of a code in the block by a point from a point. Closing тег of the PHP-block at the end of a file is not obligatory. PHP allows to use such structures: an example 10-2. A professional insert It is true. It ложь. This code works how it is expected, because when PHP meets closing теги? >, he simply deduces everything, that he finds up to the following opening тега. The given here example certainly thought up, but for a conclusion of the large blocks of the text an output(exit) from a mode of interpretation PHP is usually more effective, than sending of the text through echo (), print () or something similar. Comment PHP supports комметарии in style 'C', ' C ++ ' and environment Unix. For example: The one-lower case comments go only up to the end of a line or current block of a PHP-code, that goes before them.

It an example.

the Heading above will deduce(remove) ' It is an example '. Be close(attentive), watch(keep up) absence enclosed ' C of the '-comments, they can appear during commenting the large blocks. The one-lower case comments go only up to the end of a line or current block of a PHP-code, that goes before them. It means, what a HTML-code after //? > will be printed:? > deduces from a mode PHP and returns in a mode HTML, but // does not allow it to make. If the configuration instruction asp_tags is switched on, same occurs and at // of % >. The chapter 11. Types The contents Introduction Булев Whole Numbers with a floating point Lines Files Objects Resource NULL Pseudo-types(pseudo-!as) used in this documentation Manipulations with types Introduction PHP supports eight simple types. Four scalar types: boolean integer float (number with a floating point or 'double') string Two mixed types: array object And, at last, two special types: resource NULL For convenience of understanding in this management(manual) is used also a little pseudo-typical: mixed number callback You also can find some mentions such as double accuracy. Consider(examine) it(him) as number with a floating point two a name exist only for the historical reasons. As a rule, the programmer does not establish a type variable; it is more preferable, that it did(made) PHP during performance of the program depending on a context, in which is used variable. The remark: If you wish to check up a type and meaning(importance) of the certain expression, use var_dump (). The remark: If for debugging it is necessary simply удобочитаемое representation of a type, use gettype (). To check up on the certain type, do not use gettype (), apply for this purpose is_type of function. Some examples: If you want under duress to change a type variable, you can either result variable, or use function settype (). Pay attention, that variable, depending on her(it) such as at the given moment, in the certain situations can have different meanings(importance). More detailed information look in section of Manipulation with types. Also to you, probably, it will be interesting to see the tables of comparison of types, as in them the examples of the connected comparisons of various types are given. Булев It is the elementary type. He expresses the validity of meaning(importance) is can be either TRUE, or FALSE. The remark: Булев the type was entered in PHP 4. Syntax To define(determine) булев a type, use a key word TRUE or FALSE. Both регистро-independent. Usually you use a certain operator, which returns logic expression, and then betrays of his(its) managing design. \n "; } //... Because you can simply write if ($show_separators) { echo "


\n "; } ? > Transformation in булев a type For doubtless transformation of meaning(importance) in булев a type use reduction such as (bool) or (boolean). However in most cases you do not have necessity to use reduction of a type, as the meaning(importance) will be automatically transformed, if the operator, function or managing design requires(demands) булев argument. The Manipulations with types look also. At transformation to a logic type the following meanings(importance) are considered(examined) as FALSE: Itself булев FALSE Whole 0 (zeroes) Number with a floating point 0.0 (zeroes) Empty line and line "0" File with zero elements Object with the zero variable - members Special type NULL (including unstated variable) All other meanings(importance) are considered(examined) as TRUE (including any resource). Attention -1 it is considered TRUE, as well as any not zero (negative or positive) number! Whole Whole this number from set Z = {..., -2, -1, 0, 1, 2...}. Look also: whole any length / GMP, Number with a floating point and Any accuracy / BCMath Syntax Whole can be specified in a decimal, hexadecimal or octal notation, at will with previous is familiar (- or +). If you use an octal notation, you should anticipate number 0 (zero), for use of hexadecimal system it is necessary to put before number 0x. An example 11-1. Whole The formally possible(probable) structure whole is those: Decimal: [1-9] [0-9] * | 0 Hexadecimal: 0 [xX] [0-9a-fA-F] + Octal: 0 [0-7] + Whole: [+ -]? Decimal | [+ -]? Hexadecimal | [+ -]? Octal The size whole depends on a platform, though, as a rule, maximal meaning(importance) about two billions (this 32-bit sign). PHP does not support беззнаковые whole. Excess of the size whole If you define(determine) number exceeding limits of the whole type, it will be interpreted as number with a floating point. Also, if you use the operator, result of which job will be number exceeding limits whole(as a whole), instead of him(it) the number with a floating point will be returned. Attention Unfortunately, in PHP there was a mistake, so it not always correctly works, when the negative numbers are used. For example: when you multiply -50000 * $million, result will be -429496728. However, if both operands are positive, the problems do not arise. This mistake is eliminated in PHP 4.1.0. In PHP there is no operator of division whole. Result 1/2 will be number with a floating point 0.5. You can result meaning(importance) to whole, that always approximates it(him) in the smaller party, or to use function round (). Transformation as a whole For doubtless transformation of meaning(importance) as a whole use reduction such as (int) or (integer). However in most cases you do not have necessity to use reduction of a type, as the meaning(importance) will be automatically transformed, if the operator, function or managing design requires(demands) the whole argument. You also can transform meaning(importance) as a whole through function intval (). The Manipulations with types look also. From булева of a type FALSE will be transformed to 0 (zeroes), and TRUE - in 1 (unit). From numbers with a floating point At transformation from number with a floating point as a whole, the number will be round in the party of zero. If the number with a floating point exceeds limits whole (as a rule, it + /- 2.15e+9 = 2^31), the result will be uncertain, as whole there is no sufficient accuracy to return correct result. In this case will not be deduced(removed) prevention(warning), even the remarks! Attention Never result unknown fraction to whole, as it can sometimes give unexpected results. Look in more detail: the prevention(warning) of accuracy of numbers with a floating point. From lines Look Transformation of lines to numbers From other types Caution For other types the behaviour of transformation as a whole is not determined. Now behaviour same, as though meaning(importance) was at first transformed in булев a type. However do not rely on this behaviour, as he can change without the prevention(warning). Numbers with a floating point The numbers with a floating point (they of number of double accuracy or real numbers) can be determined through any of the following синтаксисов: Formally: LNUM [0-9] + DNUM ([0-9] * [\]. {LNUM}) | ({LNUM} [\.] [0-9] *) EXPONENT_DNUM (({LNUM} | {DNUM}) [eE] [+ -]? {LNUM}) The size whole depends on a platform, though the maximum, as a rule, ~1.8e308 with accuracy about 14 decimal figures (is a 64-bit IEEE-format). Accuracy of number with a floating point Rather often simple decimal fractions like 0.1 or 0.7 can not be transformed into the internal binary analogues without small loss of accuracy. It can result in unexpected results: for example, floor ((0.1+0.7) *10) most likely will return 7 instead of expected 8 as result of internal representation of number being actually something like 7.9999999999.... It is connected to impossibility precisely to express some fractions in a decimal notation by final number of figures. For example, 1/3 in the decimal form accepts a kind 0.3333333.... So never trust to accuracy of last figures in results with numbers with a floating point and never check them on equality. If the high accuracy is really necessary for you, you should use mathematical functions of any accuracy or gmp-functions. Transformation to number with a floating point About, when and as the lines will be transformed to numbers with a floating point read in section Transformation of lines to numbers. For meanings(importance) of other types the transformation will be same, as though the meaning(importance) at first was transformed as a whole, and then into number with a floating point. The additional information look in section Transformation as a whole. Lines The line is a character set. In PHP a symbol this same, as byte, it means, that 256 various symbols probably are equal. It also means, that PHP there is no built - in support Unicode'а. Some support Unicode'а is provided with functions utf8_encode () and utf8_decode (). The remark: There are no problems, if the line is very great. Practically there are no restrictions on the size of lines imposed PHP, so there are no absolute any reasons to worry about their length. Syntax The line can be determined by three various ways. By unary inverted commas By double inverted commas By heredoc-syntax Unary inverted commas The elementary way to define(determine) a line is to conclude her(it) in unary inverted commas (symbol '). To use unary кавычку inside a line, as well as in many other languages, she(it) is necessary for anticipating by a symbol of return slanting feature (\), т. е. To shield her(it). If the return slanting feature should go before unary кавычкой or to be at the end of a line, it is necessary продублировать her(it). Pay attention, that if you will try to shield any other symbol, the return slanting feature also will be printed! So, as a rule, there is no necessity to shield return slanting feature. The remark: In PHP 3 the message of a level E_NOTICE in this case will be given. The remark: As against two others синтаксисов, the variable and shielding sequences for special symbols meeting in lines, made in unary inverted commas, are not processed. Double inverted commas If the line is made in double inverted commas ("", PHP distinguishes a lot of managing sequences for special symbols: The table 11-1. Managing sequences Sequence meaning(importance) \n New line (LF or 0x0A (10) in ASCII) \r Return of the carriage (CR or 0x0D (13) in ASCII) \t Horizontal tabulation (HT or 0x09 (9) in ASCII) \\ Return slanting feature \ $ a mark of dollar \ " Double кавычка \ [0-7] {1,3} a sequence of symbols appropriate to regular expression, symbol in an octal notation \x [0-9A-Fa-f] {1,2} a sequence of symbols appropriate to regular expression, symbol in a hexadecimal notation We repeat, if you want мнемнонизировать any other symbol, the return slanting feature also will be printed! But the most important property of lines in double inverted commas is the processing variable. Look in more detail: processing of lines. Heredoc Other way of definition of lines is use of heredoc-syntax (" < < < "). After < < < it is necessary to specify the identifier, then there is a line, and then same identifier closing an insert. The closing identifier should begin in first столбце of a line. Besides the identifier should correspond(meet) to the same rules именования, as all other labels in PHP: to contain only alphanumeric symbols and mark of underlining(emphasis), and should begin with нецифры or mark of underlining(emphasis). Attention It is very important to note, that the line with the closing identifier does not contain other symbols, behind exception, probably, point from a point (;). It means, that the identifier should not be entered with отступом and what not can be of any blanks or marks of tabulation up to or after a point from a point. It is important also to understand, that the first symbol in front of the closing identifier should be a symbol of a new line determined in your operational system. For example, on Macintosh it \r. If this rule is broken and the closing identifier is not "pure"("clean"), it is considered, that the closing identifier is absent and PHP will continue his(its) search further. If in this case correct closing identifier and will not be found, it will call a mistake in processing with number(room) of a line in the end скрипта. The Heredoc-text behaves the same as also line in double inverted commas, thus them not having. It means, that you do not have necessity to shield inverted commas in heredoc, but you still can use set forth above managing sequences. Variable are processed, but with application complex(difficult) variable inside heredoc it is necessary to be also close(attentive), as well as at job with lines. An example 11-2. An example of definition of a heredoc-line foo = 'Foo'; this- > bar = array ('Bar1', 'Bar2', 'Bar3'); } } foo = new foo (); name = 'МоеИмя'; echo < < < EOT My name is "$name". I type $foo- > foo. Now I remove(take out) {$foo- > bar [1]}. It should deduce(remove) a capital letter 'A': \x41 EOT; ? > The remark: the support heredoc was added in PHP 4. Processing variable If the line is defined(determined) in double inverted commas, or with the help heredoc, variable inside it(her) are processed. There are two types of syntax: simple and complex(difficult). The simple syntax is easier and is convenient. He enables processings variable, meaning(importance) of a file (array) or property of object (object). The complex(difficult) syntax was entered in PHP 4 and can be recognized on braces environmental expression. Simple syntax If the interpreter meets a mark of dollar ($), he grasps so many symbols, how much it is possible to generate a correct name variable. If you want precisely to define(determine) the end of a name, conclude a name variable in braces. Be exact also can are processed an element of a file (array) or property of object (object). In indexes of a file the closing square bracket (]) designates the end of definition of an index. The same rules are applied to properties of object, as for simple variable, though with them the trick, as with variable is impossible. 'red', 'banana' = > 'yellow'); // Works, but notice, that outside of inverted commas of a line it works in another way echo " A banana is $fruits [banana]. "; // Works echo " A banana is {$fruits [' banana ']}. "; // Works, but PHP, as is described below, at first searches // Constant banana. echo " A banana is {$fruits [banana]}. "; // Does not work, use braces. It will call a mistake of processing. echo " A banana is $fruits [' banana ']. "; // Works echo " A banana is ". $fruits ['banana']. "."; // Works echo " This square is $square- > width meters broad. "; // Does not work. For the decision see complex(difficult) syntax. echo " This square is $square- > width00 centimeters broad. "; ? > For something more complex(difficult) you should use complex(difficult) syntax. Complex(difficult) (figured) syntax He is called complex(difficult) not because is difficult in understanding, that is why that allows to use complex(difficult) expressions. Actually, you can switch on any meaning(importance) which is taking place in space of a name in a line with this syntax. You simply write down expression in the same way, as well as outside of a line, and then conclude it(him) in {and}. As you can not shield '{', this syntax will be distinguished only when $ follows directly for {. (Use " {\ $ " or " \ {$ " to display " {$ "). Some explaining examples: width} 00 centimeters. "; // Works echo " It works: {$arr [4] [3]} "; // It is incorrect for the same reason, as $foo [bar] incorrectly outside of // Line. In other words, it will work still, // But as PHP at first searches for a constant foo, it will call // Mistake of a level E_NOTICE (uncertain constant). echo " It is wrong: {$arr [foo] [3]} "; // Works. At use многомерных of files, inside // Of lines always use braces echo " It works: {$arr [' foo '] [3]} "; // Works. echo " It works: ". $arr ['foo'] [3]; echo " you even can write down {$obj- > values [3] - > name} "; echo " This meaning(importance) variable on a name $name: {$ {$name}} "; ? > Access to a symbol in a line and his(its) change The symbols in lines can be be to be used and modify, having defined(determined) their displacement rather beginnings of a line, since zero, in braces after a line. The remark: For maintenance of return compatibility, you still have an opportunity to use in the same purposes of a bracket of a file. However, since PHP 4, this syntax is undesirable to use. Example 11-3. Some examples of lines Useful functions and operators The lines can be incorporated through the operator '.' (Point). Pay attention, the operator of addition '+' here does not work. The additional information the Line operators look in section. For updating lines there is a set of useful functions. The basic functions are described in section of line functions, function of regular expressions for the extended search and replacement (in two parts: Perl and POSIX extended). Also there are functions for URL-lines, and function for enciphering / decoding of lines (mcrypt and mhash). At last, if all of you yet have not found, that searched, the functions for a symbolical type look also. Transformation to a line You can transform meaning(importance) to a line, using reduction (string), or function strval (). In expressions, where the line is necessary, the transformation occurs automatically. It occurs, when you use functions echo () or print (), or when you compare meaning(importance) variable to a line. The perusal of sections of a management(manual) will make Types and Manipulations with types the following by more clear. Look also settype (). Булево (boolean) the meaning(importance) TRUE will be transformed to a line "1", and the meaning(importance) FALSE is represented as " " (empty line). By this way you can transform meanings(importance) to both parties - from булева such as in line and on the contrary. Whole (integer) or the number with a floating point (float) will be transformed to a line submitted by number, consisting from his(its) figures (including a parameter of a degree for numbers with a floating point). The files will always be transformed to a line "Array", so you can not display contents of a file (array), using echo () or print () to learn(find out), that he contains. To see(overlook) one element, you need to make something like echo $arr ['foo']. Below advice(councils) looks how to display / see all contents. The objects will always be transformed to a line "Object". If you want to deduce(remove) meaning(importance) of the variable - member of object (object) with the purpose of debugging, read the following paragraphs. If you want to receive a name of a class of required object, use get_class (). The resources will always be transformed to lines with structure " Resource id *1 ", where 1 is unique number(room) of a resource (resource), appropriated(given) to him PHP during performance. If you want to receive a type of a resource, use get_resource_type (). NULL will always be transformed to an empty line. As you could see above, conclusion of files, objects or resources does not give you of any useful information on meanings(importance). More suitable way of a conclusion of meanings(importance) for debugging - to use functions print_r () and var_dump (). You also can transform meanings(importance) PHP to lines for a constant storage. This method is called сериализацией and can be executed through function serialize (). Besides if in your installation PHP there is a support WDDX, you can сериализовать of meaning(importance) PHP in structures XML. Transformation of lines to numbers If the line is distinguished as numerical meaning(importance) the resulting meaning(importance) and type is defined(determined) as is shown further. The line will be recognized as float, if she contains any of symbols '.', 'e', or 'E'. Differently she will be determined as whole. The meaning(importance) is defined(determined) by an initial part of a line. If the line begins with correct numerical meaning(importance), this meaning(importance) will be used. Differently meaning(importance) will be 0 (zeroes). The correct numerical meaning(importance) is of one or more figures (able to contain a decimal point), at the request of anticipated is familiar, with the subsequent unessential parameter of a degree. The parameter of a degree is 'e' or 'E' with subsequent in one or more figures. More detailed information on this transformation look in section about strtod (3) documentation Unix. If you want to test any of examples of this unit, you can copy and insert it(him) and following line to see, that occurs: \n "; ? > Do not expect to receive a code of a symbol, having transformed it(him) as a whole (as you could make, for example, in C). For transformation of symbols to their codes and back use functions ord () and chr (). Files Actually file in PHP is the ordered display, which establishes conformity between meaning(importance) and ключем. This type is optimized in several directions, therefore you can use it(him) as actually file, list (vector), хэш-table (being realization of a map), dictionary, collection, stack, turn or, it is possible, as something else. As you can have as meaning(importance) other file PHP, you can also easily emulate trees. The explanation of these structures of the data leaves for frameworks of the given help management(manual), but you will find as a minimum one example of each of them. Behind the additional information you can address to the appropriate literature on this extensive theme. Syntax Definition with the help array () The file can be created by a language design array (). As parameters she accepts the certain quantity(amount) of the pairs, divided(shared) by points, key = > value (key = > meaning(importance)). array ([key = >] value ,... ) // key can be integer or string // value can be any meaning(importance) "bar", 12 = > true); echo $arr ["foo"]; // bar echo $arr [12]; // 1 ? > key can be either integer, or string. If the key is a standard representation integer, he and will be interpreted (i.e. "8" will be perceived as 8, whereas "08" will be interpreted as "08"). In PHP there is no difference between index and associative files; there is only one type of a file, which can contain both numerical, and line indexes. The meaning(importance) can be any available in PHP of a type. array (6 = > 5, 13 = > 9, "a" = > 42)); echo $arr ["somearray"] [6]; // 5 echo $arr ["somearray"] [13]; // 9 echo $arr ["somearray"] ["a"]; // 42 ? > If you do not specify a key for the given meaning(importance), the maximal numerical index undertakes and the new key will be equal to this maximum + 1. If you specify key, to which the meaning(importance) is already appropriated(already given), it will be rewritten. 43, 32, 56, "b" = > 12); //... To this file array (5 = > 43, 6 = > 32, 7 = > 56, "b" = > 12); ? > Attention Since PHP 4.3.0, the above described behaviour of generation of an index is changed. Now, if you will use a file, in which maximal at the present moment the negative key is, the following created key will be zero (0). Earlier new index became the largest existing key + 1, as well as at positive indexes. Using as a key TRUE you receive a key 1 such as integer. Using as a key FALSE you receive a key 0 such as integer. Using as a key NULL, you receive an empty line. Use as a key of an empty line will create (or will rewrite) key with an empty line and his(its) meaning(importance); it not same, that use of empty square brackets. You can not use as keys files or objects. It will call the prevention(warning): Illegal offset type (' an Inadmissible type of displacement '). Creation / updating with the help of syntax of square brackets Also you can change an existing file, obviously establishing meanings(importance) in him. It is carried out by assignment of meanings(importance) to a file at the instruction(indication) in brackets of a key. Besides you can lower(omit) a key, in this case add to a name a variable empty pair of brackets (" [] "). $arr [key] = value; arr [] = value; // key can be integer or string // value can be any meaning(importance) If the file $arr does not exist yet, he will be created. Thus, it is one more way to define(determine) a file. For change of the certain meaning(importance) simply appropriate(give) to an element with his(its) key new meaning(importance). If you want to remove a pair key / meaning, you need to use function unset (). 1, 12 = > 2); arr [] = 56; // In this place скрипта it // Is equivalent $arr [13] = 56; arr ["x"] = 42; // It adds to a file new // Element with a key "x" unset ($arr [5]); // It deletes an element from a file unset ($arr); // It deletes a file completely ? > The remark: As was already spoken above, if you do not specify in brackets of a key, will be taken maximal from existing integer indexes, and a new key will be this maximal meaning(importance) + 1. If integer indexes still no, a key will be 0 (zeroes). If you specify key, to which the meaning(importance) is already appropriated(already given), it will be rewritten. Attention Since PHP 4.3.0, the above described behaviour of generation of an index is changed. Now, if you will use a file, in which maximal at the present moment the negative key is, the following created key will be zero (0). Earlier new index became the largest existing key + 1, as well as at positive indexes. Pay attention, that the maximal numerical key used for it not necessarily should exist in a file at the present moment. He simply should exist from the moment of last переиндексирования of a file. It illustrates the following example: $value) { unset ($array [$i]); } print_r ($array); // We create an element (pay attention, that a new key will be 5, // Instead of 0, as you probably expected). array [] = 6; print_r ($array); // Переиндексация: array = array_values ($array); array [] = 7; print_r ($array); ? > The above-stated example will deduce(remove) the following: Array ( [0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4 [4] = > 5 ) Array ( ) Array ( [5] = > 6 ) Array ( [0] = > 6 [1] = > 7 ) Useful functions For job with files there is enough of useful functions. Look section of function for job with files. The remark: the function unset () allows to delete keys of a file. Pay attention, that the file will not be переиндексирован. If you used only " usual numerical indexes " (increased on unit, since zero), you can переиндексировать a file using array_values (). 'one', 2 = > 'two', 3 = > 'three'); unset ($a [2]); /* Will give a file submitted so: a = array (1 = > 'one', 3 = > 'three'); Instead of so: a = array (1 = > 'one', 2 = > 'three'); */ b = array_values ($a); // Now $b it array (0 = > 'one', 1 = > 'three') ? > The managing design foreach exists specially for files. She gives an opportunity easily to pass on a file. The file does(makes) and does not do(make) Why $foo [bar] it incorrectly? You always should conclude an index of an associative file in inverted commas. For example, write $foo ['bar'], instead of $foo [bar]. But why $foo [bar] it incorrectly? Probably, you met in old скриптах the following syntax: It is incorrect, though works. Then why it is incorrect? The reason that this code contains a uncertain constant (bar), instead of line ('bar' - pay attention to inverted commas), and PHP in the future can define(determine) a constant, which unfortunately for your code will have the same name. It works, because PHP automatically will transform a naked line (line, not made in inverted commas, which does not correspond(meet) to any of known symbols) in a line, which contains a naked line. For example, if the constant with a name bar is not determined, PHP will replace bar with a line 'bar' and uses her(it). The remark: It does not mean, that is necessary always to conclude a key in inverted commas. There is no necessity to conclude in inverted commas of a constant or variable, as it will prevent PHP to process them. The remark: the above-stated code will deduce(remove) the following: We check 0: Notice: Undefined index: $i in /path/to/script.html on line 9 Poorly: Well: 1 Notice: Undefined index: $i in /path/to/script.html on line 11 Poorly: Well: 1 We check 1: Notice: Undefined index: $i in /path/to/script.html on line 9 Poorly: Well: 2 Notice: Undefined index: $i in /path/to/script.html on line 11 Poorly: Well: 2 Additional examples demonstrating this fact: 'apple', 'veggie' = > 'carrot'); // Is correct print $arr ['fruit']; // apple print $arr ['veggie']; // carrot // It is incorrect. It works, but because of uncertain constant with // By a name fruit also causes a mistake PHP of a level E_NOTICE // // Notice: Use of undefined constant fruit - assumed 'fruit' in... print $arr [fruit]; // apple // Let's define(determine) a constant to show, that // Occurs. We shall appropriate(give) to a constant with a name fruit meaning(importance) 'veggie'. define ('fruit', 'veggie'); // Now pay attention to a difference print $arr ['fruit']; // apple print $arr [fruit]; // carrot // Inside a line it is normal. Inside lines of a constant not // Are considered(examined), so a mistake E_NOTICE here will not take place print " Hello $arr [fruit] "; // Hello apple // With one exception: braces around of files inside // Of lines allow constants is there print " Hello {$arr [fruit]} "; // Hello carrot print " Hello {$arr [' fruit ']} "; // Hello apple // It will not work and will call a mistake of processing, such as: // Parse error: parse error, expecting T_STRING ' or T_VARIABLE ' or T_NUM_STRING ' // It, certainly, also приложимо and to use in lines auto global variable print " Hello $arr [' fruit ']'; print " Hello $ _GET [' foo ']'; // One more opportunity - конкатенация print "Hello". $arr ['fruit']; // Hello apple ? > When you will translate error_reporting () in a mode of display of mistakes of a level E_NOTICE (such as E_ALL), you will see these mistakes. By default error_reporting is established them to not display. As the syntax is specified in section, inside square brackets ('[' and ']') there should be an expression. It means, that you can write similarly to this: It is an example of use of meaning,(importance,) returned by function, as an index of a file. PHP are known as well constants, as you, probably, saw a mention E_* earlier. Pay attention, that E_ERROR is the same correct identifier, as well as bar in the first example. But last example as a matter of fact is equivalent to such record: As E_ERROR corresponds(meets) 1 and т. д. As we already have explained in the above-stated examples, $foo [bar] still works, but it is incorrect. It works, as according to the syntax bar it is expected as a constant. However, in this case constant with a name bar does not exist. In such case PHP assumes, that, having written bar, you had in view of a line "bar", but have forgotten to specify inverted commas. So in it bad? Sometime in the future the command(team) of the developers PHP probably will wish to add one more constant or key word, or you can enter into your application one more constant and then you can have problems. For example, you can not use thus words empty any more and default, as they are preserved key words. The remark: Let's repeat, inside a line (string), made in double inverted commas correct is to not surround indexes of a file by inverted commas, therefore " $foo [bar] " is correct. In more detail why - the above-stated examples, and also section processing variable in lines look. Transformation to a file For any of types: integer, float, string, boolean and resource, if you will transform meaning(importance) to a file, you receive a file with one element (with an index 0), being scalar meaning(importance), from which you have begun. If you will transform to a file object (object), you receive as elements of a file of property (variable - members) of this object. Keys will be names of the variable - members. If you will transform to a file meaning(importance) NULL, you receive an empty file. Comparison The files can be compared through function array_diff () and Operators of files. Examples The type a file in PHP is very flexible, therefore we shall result here some examples to show to you all opportunities of files. 'red', 'taste' = > 'sweet', 'shape' = > 'round', 'name' = > 'apple', 4 // a key will be 0 ); // Completely corresponds(meets) a ['color'] = 'red'; a ['taste'] = 'sweet'; a ['shape'] = 'round'; a ['name'] = 'apple'; a [] = 4; // a key will be 0 b [] = 'a'; b [] = 'b'; b [] = 'c'; // Will create a file array (0 = > 'a', 1 = > 'b', 2 = > 'c'), // Or it is simple array ('a', 'b', 'c') ? > Example 11-4. Use array () 4, ' OS = > ' Linux ', 'lang' = > 'english', ' short_tags = > true ); // Extremely numerical keys array = array (7, 8, 0, 156, -10 ); // This same, as array (0 = > 7, 1 = > 8...) switching = array (10, // a key = 0 5 = > 6, 3 = > 7, 'a' = > 4, 11, // the key = 6 (maximal numerical index was 5) '8' = > 2, // a key = 8 (number!) '02' = > 77, // a key = '02' 0 = > 12 // the meaning(importance) 10 will be rewritten on 12 ); // Empty file empty = array (); ? > Example 11-5. A collection The result of job given скрипта will be the following: It is pleasant to you red? It is pleasant to you dark blue? It is pleasant to you green? It is pleasant to you yellow? Pay attention, that now it is impossible to change meanings(importance) of a file in such cycle directly. However it is possible to make so: an example 11-6. A collection $color) { // Will not work: // $color = strtoupper ($color); // Works: colors [$key] = strtoupper ($color); } print_r ($colors); ? > The result of job given скрипта will be the following: Array ( [0] = > RED [1] = > DARK BLUE [2] = > GREEN [3] = > YELLOW ) The following example creates a file, beginning from unit. An example 11-7. An index beginning from unit 'January', 'February', 'March'); print_r ($firstquarter); ? > The result of job given скрипта will be the following: Array ( [1] = > 'January' [2] = > 'February' [3] = > 'March' ) Example 11-8. Filling of a file The files are ordered. You can change the order of elements, using various functions of sorting. For the additional information look section of function for job with files. You can count up quantity(amount) of elements in a file, using function count (). Example 11-9. Sorting of a file As the meaning(importance) of a file can be everything, he(it) also can be other file. Thus you can create рекурсивные and многомерные files. Example 11-10. Рекурсивные and многомерные files array ("a" = > "orange", "b" = > "banana", "c" = > "apple" ), "Numbers" = > array (1, 2, 3, 4, 5, 6 ), "дырки" = > array ("first", 5 = > "second", "Third" ) ); // Some examples of access to meanings(importance) of the previous file echo $fruits ["дырки"] [5]; // "second" will print echo $fruits ["fruit"] ["a"]; // will print "orange" unset ($fruits ["дырки"] [0]); // "first" will remove // Will create new многомерный a file juices ["apple"] ["green"] = "good"; ? > Pay attention, that at giving a file always there is copying meaning(importance). To copy a file under the reference, you are necessary need the operator of the reference. Objects Initialization of object For initialization of object the expression new, creating in a variable copy of object is used. do_foo (); ? > The complete consideration is made in section Classes and Objects. Transformation to object If the object will be transformed to object, he does not change. If the meaning(importance) of any other type will be transformed to object, the new copy of the built - in class stdClass is created. If the meaning(importance) was empty, the new copy also will be empty. At any by the other meaning(importance) it will be contain in the variable - member scalar. scalar; // will deduce(remove) 'ciao' ? > Resource The resource is special variable, containing the reference to an external resource. The resources are created and are used by special functions. The complete list of these functions and appropriate types of resources look in the application. The remark: the type a resource was entered in PHP 4 Transformation to a resource As a type the resource contains the special indexes on open files, connection with a database, area of the image and so forth, you can not transform any meaning(importance) to a resource. Clearing of resources In connection with system of calculation of the references entered in движке Zend PHP 4 automatically is defined(determined), that the resource does not refer anywhere (as in Java) more. When it occurs, all resources, which were used for the given resource, are released(exempted) by the collector of dust. For this reason it is improbable, that will be ever necessary to release(exempt) memory manually, using any free_result function. The remark: the constant references of a database are special, they are not destroyed by the collector of dust. Look also section about constant connections. NULL The special meaning(importance) NULL speaks that this variable has no meaning(importance). NULL is единственно possible(probable) meaning(importance) such as NULL. The remark: the empty type was entered in PHP 4 Variable it is considered NULL if To her the constant NULL was appropriated(given). To her any meaning(importance) was not appropriated(given) yet. She was removed with the help unset (). Syntax There is only one meaning(importance) such as NULL - регистро-independent key word NULL. Look also is_null () and unset (). Pseudo-types(pseudo-!as) used in this documentation mixed mixed speaks that parameter can accept set (but not necessarily all) types. gettype (), for example, accepts all types PHP, whereas str_replace () accepts lines and files. number number speaks that parameter can be either integer, or float. callback Some functions, such as call_user_func () or usort () accept as parameter the callback-function.s, determined by the user, of Callback-function can be not only simple functions, but also methods of objects, including static methods of classes. The PHP-function is passed simply as a line of its(her) name. You can pass function, any built - in or determined by the user, behind exception array (), echo (), empty (), eval (), exit (), isset (), list (), print () and unset (). The method of the created object is passed as a file containing object in an element with an index 0 and name of a method in an element with an index 1. The methods of static classes also can be transferred(handed) without creation of a copy of object by transfer of a name of a class instead of a name of object in an element with an index 0. Example 11-11. Examples of callback-functions If last two examples to you are not clear, look Transformation of lines to numbers. If you want, that variable should be under duress calculated as the certain type, look undressed reduction of types. If you want to change a type variable, look settype (). If you want to test any of examples given in the given section, you can use function var_dump (). The remark: the behaviour of automatic transformation in a file at the present moment is not determined. As PHP (for the historical reasons) supports индексирование in lines with use of the same syntax, as well as at индексировании of a file the above-stated example results in a problem: whether it is necessary $a to become a file, which first element will be "f" or "f" should become the first symbol of a line $a? The current version PHP perceives the second giving as definition of displacement of a line, therefore $a becomes "f", the result of this automatic transformation should, however, be considered(examined) as uncertain. In PHP 4 for access to symbols of a line the new syntax of braces was entered, use this syntax instead of above-stated: For the additional information look undressed Access to a symbol in a line. Reduction of types The reduction of types in PHP works the same as and in C: the name of a required type enters the name in parentheses before resulted(brought) variable. The following reductions of types are supposed: (int), (integer) - reduction to an integer (bool), (boolean) - reduction to булеву to a type (float), (double), (real) - reduction to number with a floating point (float) (string) - reduction to a line (array) - reduction to a file (object) - reduction to object Pay attention, that inside brackets the blanks and symbols of tabulation are supposed, therefore following is equivalent on the action: The remark: Instead of reduction variable to a line, you can conclude her(it) in double inverted commas. Probably, it is not absolutely clear, that occurs at reduction between types. For the additional information the sections look: Transformation in булев a type Transformation to an integer Transformation to number with a floating point Transformation to a line Transformation to a file Transformation to object Transformation to a resource The tables of comparison of types