


Array-related functions in PHP collected by harry potter and the deathly h
From the first introduction to ASP to PHP, I feel that one of the strengths of PHP is the richness of built-in functions. For example, the PHP date and time functions I learned earlier, the related functions for reading and writing files, etc. all show that PHP is more professional and easier for users to use. Handy.
At first I was very excited about the rich functions of PHP functions. As I came into contact with more and more almost abnormal functions, I suddenly thought of the scarcity of ASP built-in functions. To complete a special function, you often need to customize the function. As the number of applications increases, I actually have a set of commonly used function libraries. However, now in PHP, these functions have long been standardized, standardized and condensed into built-in functions for direct use. Former ASP developers have become ordinary users of PHP.
But on second thought, the existence of these functions and a large number of PHP functions at least shows that PHP is more professional; at the same time, it should be very fast and easy to use when processing our daily PHP programs, which makes developers no longer worry about it. Basic functions and detailed functions are removed from custom functions, and the main focus is on building more powerful program modules. Therefore, I have strengthened my belief in taking a look at PHP functions, but I think that in the future development process, the PHP function manual should be a portable book.
Of course, there is no need to discuss the debate about the advantages and disadvantages of ASP and PHP. Learning and understanding can help you understand the truth.
To get back to the subject, there are too many PHP functions to prevent forgetting, so every time I read a type of function, I make a summary and collection work, and write a log for convenience.
1. Definition and initialization of array
What is an array? An array is a programming structure that is a variable that stores a set or series of values.
For example, the identity registration of individuals during the census, such as name, gender, ethnicity, birth, etc., can be used as an array.
Creating an array in PHP is defined using the array() structure, for example:
$people=array('name','sex','nation','brith');
How to display the value of each element in the array? We use an index starting from 0, and the index number is in square brackets after the variable name, for example:
$people=array('name','sex','nation','birth') ;
echo $people[2];
?>
The output $people[2] shows nation (the first item of the index counts from 0).
PHP not only supports numerical index arrays, but also supports related arrays. The so-called related array means that you can use custom keywords to replace unintuitive numerical indexes, such as:
$peoples=array('xm'=>'name','xb'=>'sex' ,'mz'=>'nation','cs'=>'birth');
echo $peoples['cs'];
?>
Using related arrays makes the selection of output intuitive (no need to pre- Calculate the index number and then output), use the "=>" symbol between the defined keyword and value.
According to the two display methods of PHP array elements, numbers can be automatically created directly without array() declaration and initialization like variables. For example
$people[0]='name';
$people[1]='sex';
$people[2]='nation';
$people[3]='brith';
or
$peoples ['xm']='name';
$peoples['xb']='sex';
$peoples['mz']='nation';
$peoples['cs']='birth';
The size of the array changes dynamically based on how many elements are added.
2. Display of array elements
No matter $people[2] or $peoples['cs'] used above, it only outputs the array element value of the known clear position. How to quickly output all or For some array elements, using a loop statement is undoubtedly the fastest way.
$people=array('name','sex','nation','birth');
for ($i=0;$i<4;$i++)
echo "$people[ $i] ";
?>
In addition to using a for loop that knows the number of loops, you can also use a foreach statement that does not require the number of loops.
$people=array('name','sex','nation','birth');
foreach($people as $xiangmu)
echo $xiangmu;
?>
$xiangmu variable The values of each element in the array will be saved and displayed in sequence. Of course, in order to distinguish the output data, a space can be output after the array elements:
echo $xiangmu." ";
Note: English periods (.) can merge string connections into new strings, see Intimate Contact PHP Variables and constants study notes
The above introduces the array-related functions in PHP collected by harry potter and the deathly h, including the content of harry potter and the deathly h. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
