


A brief discussion on PHP source code 10: About array_keys, array_values functions
This article mainly introduces a brief discussion on PHP source code 10: Regarding the array_keys and array_values functions, it has a certain reference value. Now I share it with you. Friends in need can refer to it
The first of the new year This article, first of all, I would like to wish all my friends a Happy New Year
I have some time today to read the code and write something as a souvenir!
array array_keys (array input [, mixed search_value [, bool strict]] )
array_keys() Returns the key name of the number or string in the input array.
If the optional parameter search_value is specified, only the key name of the value will be returned. Otherwise all keys in the input array will be returned. Since PHP 5, you can use the strict parameter to perform equality comparisons (===).
The array_keys function is implemented in line 2416 of the standard/array.c file PHP_FUNCTION(array_keys)
The program follows the usual PHP style and first determines whether the input is correct. If there is a third parameter, Then the function to determine the size uses is_identical_function (the is_equal_function function is used by default)
Then initialize the returned array, traverse the given array, take the key value of each element, and assign it to the returned array. This key value is divided into There are two types of numbers and strings. The most important function is the hash operation function zend_hash_get_current_key_ex (get the key value of the current element)
ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, uint *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos){ Bucket *p; p = pos ? (*pos) : ht->pInternalPointer; IS_CONSISTENT(ht); if (p) { if (p->nKeyLength) { // 数字型的nKeyLength长度为0 if (duplicate) { *str_index = estrndup(p->arKey, p->nKeyLength - 1); } else { *str_index = p->arKey; // /* arKey存储key名称(字符串类型的key)必须是最后一个成员,*/ } if (str_length) { *str_length = p->nKeyLength; } return HASH_KEY_IS_STRING; } else { *num_index = p->h; // 存储数字key值 return HASH_KEY_IS_LONG; } } return HASH_KEY_NON_EXISTANT;}
The understanding of this function mainly depends on the understanding of the bucket definition
For bucket-related content, please go to http://www.php.cn/php-weizijiaocheng-405316.html
array array_values (array input)
array_values() Returns the input array All values in and create numerical indexes for them.
The array_values function is basically similar to the array_keys function implementation, and it also lacks a zend_hash_get_current_key_ex operation and an operation to determine the value type.
The above is the entire content of this article. I hope it will be helpful to everyone's learning. More For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
A brief discussion of PHP source code nine: Introduction to array_unshift, array_push
A brief discussion of PHP source code eight : Introduction to array_pop, array_shift
A brief discussion of PHP source code 7: About nl2br, ltrim, rtrim, trim functions
The above is the detailed content of A brief discussion on PHP source code 10: About array_keys, array_values functions. For more information, please follow other related articles on the PHP Chinese website!

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...

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.

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

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...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

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.
