Php entry-level learning functions, php entry-level functions

Source: Internet
Author: User

Php entry-level learning functions, php entry-level functions

 

1. join ():

Definition and usage

The join () function returns a string composed of array elements.

The join () function is the alias of the implode () function.

Note: The join () function accepts the order of two parameters. However, for historical reasons, explode () does not work. You must ensure that the separator parameter is prior to the string parameter.

Note: The separator parameter of the join () function is optional. However, we recommend that you use two parameters for backward compatibility.

Syntax

Join (separator, array)

Parameters

Separator: (optional) specifies the content to be placed between array elements. The default value is "" (empty string) or "+", "-", and so on.

Array: required. It must be an array of strings.

2. array_keys ()

Definition and usage:

The array_keys () function returns a new array containing all the key names in the array.

If the second parameter is provided, only the key name of the value is returned.

For example:

<? Php

$ A = array ("Volvo" => "XC90", "BMW" => "X5", "Toyota" => "Highlander ");

Print_r (array_keys ($ ));

?>

Running result:

Array ([0] => Volvo [1] => BMW [2] => Toyota)

3. array_values ():

Definition and usage:

The array_values () function returns an array containing all the key values in the given array without retaining the key name.

Tip: The returned array uses the value key, which starts from 0 and increments with 1.

For example:

<? Php

$ A = array ("Name" => "Bill", "Age" => "60", "Country" => "USA ");

Print_r (array_values ($ ));

?>

Running result:

Array ([0] => Bill [1] => 60 [2] => USA)

4. mysql_query () function:

Mysql_query () If a query statement is put in it, the returned resource is. To put it bluntly, it is the data result set you want to query. If it contains statements such as add, delete, modify, and so on, the returned values are true or false.

If you want to use this data result set, you must use functions such as mysql_result (), mysql_fetch_array (), and mysql_fetch_row () to obtain the data, that is, mysql_query () must be used with the preceding functions.

5. mysql_fetch_assoc ():

Mysql_fetch_assoc extracts a row of records from the result set, and the resource pointer jumps down,

That is to say, when mysql_fetch_assoc is used, a new row of records will be obtained,

Similarly, every execution of mysql_fetch_assoc takes a new row until the last row is retrieved,

If the next row does not exist, false is returned.

To sum up:

In your first example,

$ S_as = mysql_fetch_assoc ($ s_re );

While ($ s_as)

Is the first row of the result set. The first row is not empty, so $ s_as is not equal to false. Therefore, when you use while ($ s_as, equivalent to while (true), it is an endless loop and should be changed:

$ S_as = mysql_fetch_assoc ($ s_re );

While ($ s_as ){

$ Arr [] = $ s_as;

$ S_as = mysql_fetch_assoc ($ s_re); // you did not write this line, so $ s_as is never false, causing an endless loop.

}

In the second example, while ($ s_as = mysql_fetch_assoc ($ s_re) is different. Each time a row is taken, when the last row is obtained, there will be no more rows, mysql_fetch_assoc returns the flash, that is, $ s_as = false, and the while loop stops.

6. substr (string, start, length ):

Process string.

Start: specifies where the substring starts.

Length: (optional) specifies the length of the string to be returned. The end of the string is known by default.

7. foreach ():

Used to traverse operations or output arrays. foreach () can only be used to traverse arrays or objects. When trying to use it for other data types or an uninitialized variable, an error will occur.

Syntax:

Foreach (array as $ value)

Statement

// Or:

Foreach (array as $ key => $ value)

Statement

In the preceding syntax, each cycle assigns the value of the current unit to $ value and the pointer inside the array moves one step forward. In the second syntax format, the key name of the current Unit is also assigned to the variable $ key in each loop.

Https://git.coding.net/ssssdy/New_ArtclePub.git

Https://git.coding.net/ssssdy/New_ArtclePub.git

8. File Path processing functions

Basename (): Get the file name of the file path.

Dirname (): Get the directory of the file path

9. string processing functions

Stripos (string, find, start)

Definition and usage

The stripos () function is used to locate the first occurrence of a string in another string (Case Insensitive ).

Note:The stripos () function is case-insensitive.

Note:This function is binary secure

10. floor ()Function:Round down to the nearest integer.

11.Feof () function:

Function prototype:
Int feof (FILE * stream );
Header file:
Stdio. h
Return Value:
A non-zero value indicates that the end of the file has been reached.
Function Description:Feof () is used to detect whether the end of the file is read, and the ending number stream is the object pointer returned by fopen. if the end of the file is reached, a non-zero value is returned. Otherwise, 0 is returned. Note: feof () function, after reading the last character of the file, feof () of C Language () the function returns 0, indicating that the end of the file is not reached. feof () returns a non-zero value only when fgetc () reads one character backward (that is, beyond the last character, the end of the file. 12. fscanf ()

The fscanf function is used to format the input from a stream. fscanf ends when there is a space or a line change. Note that the space also ends. This is different from fgets. fgets does not end when it encounters a space.

Prototype: int fscanf (FILE * stream, char * format, [argument...]);

Return Value: return the number of input items actually converted and assigned values.

% D: Read a decimal integer.

% I: reads decimal, octal, and hexadecimal integers. It is similar to % d. However, the hexadecimal value is distinguished by the Data prefix during compilation, if "0x" is added, the hexadecimal format is used. If "0" is added, the octal format is used. For example, when the string "031" uses % d, It is counted as 31, but when % I is used, it is counted as 25.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.