Home  >  Article  >  Backend Development  >  PHP Basics_PHP Tutorial

PHP Basics_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:14:50964browse

1 Output data to the browser: print(), echo(), printf(), sprintf(),

  • The print() and echo() statements both output the data passed into it to the browser
  • pintf() outputs a mixed statement consisting of static text and dynamic information stored in one or more variables
  • sprintf() has the same function as print(), but it assigns the output to a character string instead of directly presenting it to the browser

2 Type-related functions:

  • Get type gettype() string gettype(mixed <code>string gettype(mixed <span>var</span>) var
  • )
Conversion type settype() boolean settype(mixed var, string type)


3 Variable declaration: Variables always start with the dollar sign $, followed by the variable name.

4 The heredoc syntax provides a convenient way to output large amounts of text. Using two identical identifiers, the text between the two identical identifiers is
php$website httpsecho
EXCERPT //Identifier>......//Text

excerpt; //Identifier

5 foreach statement: traverse elements (such as arrays) which has two forms
  • foreach (array_expr
    as
  • $value){
  • statement } foreach (array_expr as
    $key$value){
  • statement
}

:
>echo
:
>;
foreach ($links
as $link) {echo

;}> ( ,                                                                                                                       PHP Scripting Language" echo "Online Resources>b>br < span ";foreach ($links as $title=>>echo "a href"http title
>} 6 File contains statements: Make the code reusable and modular, improve efficiency, refuse to work overtime, and cherish the life of programmers.

include()、include_once()、require() ***The difference between require() and include() is that regardless of the location of require(), the specified file must be included in the script of require().


7 Returning multiple values ​​from a function: Suppose you want to create a function that gets user data from the database (name, email, address, phone number), and then returns all the user's personal information to the caller. To implement returning multiple values, the language construct list() can satisfy your wishes.

<hr> <p>8 Array<code><code> Creating arrays: There are many differences between PHP and other computer languages ​​when creating arrays. There is no need to specify its size, and there is no need to declare it first when using numbers.

The related functions are

    • explode(separator, string, limit) //Split the string into an array, the first two parameters are required.
    • range(fist, secend,step) //Create and return an array containing elements in the specified range. The first two parameters are required.
    • is_array(mixed variable) //Determine whether the variable type is an array type.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440263.htmlTechArticle1 Output data to the browser: print(), echo(), printf(), sprintf(), print () and echo() statements both output the data passed into it to the browser pintf() outputs static text and one or more...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn