Working with Arrays
Arrays are stored in HashTable strucures, and have the zval type IS_ARRAY. The API functions for creating, destroying and manipulating these structures as variables are documented here and can be found in Zend/zend_API.h
Prototype | Description |
---|---|
void array_init(zval* pzval) |
initializes the variable as a HashTable , setting type and appropriate destructor function for the HashTable |
void array_init_size(zval* pzval) |
initializes the variable as array_init with a minimum of size buckets |
Note:
Do not squint too hard looking for array_destroy: to destroy a variable array you should call
zval_ptr_dtor
on the variable, if there are no other references to the variable it will result in the array being destroyed.
Prototype |
---|
int add_index_long(zval* pzval, ulong index, long value) |
int add_index_null(zval* pzval, ulong index) |
int add_index_bool(zval* pzval, ulong index, zend_bool value) |
int add_index_bool(zval* pzval, ulong index, zend_bool value) |
int add_index_resource(zval* pzval, ulong index, uint value) |
int add_index_double(zval* pzval, ulong index, double value) |
int add_index_string(zval* pzval, ulong index, char* string, zend_bool duplicate) |
int add_index_stringl(zval* pzval, ulong index, char* string, uint length, zend_bool duplicate) |
int add_index_zval(zval* pzval, ulong index, zval* value) |
int add_next_index_long(zval* pzval, long value) |
int add_next_index_null(zval* pzval) |
int add_next_index_bool(zval* pzval, zend_bool value) |
int add_next_index_resource(zval* pzval, uint value) |
int add_next_index_double(zval* pzval, double value) |
int add_next_index_string(zval* pzval, const char* string, zend_bool dulpicate) |
int add_next_index_stringl(zval* pzval, const char* string, uint length, zend_bool duplicate) |
int add_next_index_zval(zval* pzval, zval* value) |
Prototype |
---|
int add_assoc_long(zval* pzval, const char* key, long value) |
int add_assoc_long_ex(zval* pzval, const char* key, uint klen, long value) |
int add_assoc_null(zval* pzval, const char* key) |
int add_assoc_null_ex(zval* pzval, const char* key, uint klen) |
int add_assoc_bool(zval* pzval, const char* key, zend_bool value) |
int add_assoc_bool(zval* pzval, const char* key, zend_bool value) |
int add_assoc_bool_ex(zval* pzval, const char* key, uint klen, zend_bool value) |
int add_assoc_resource(zval* pzval, const char* key, uint value) |
int add_assoc_resource_ex(zval* pzval, const char* key, uint klen, uint value) |
int add_assoc_double(zval* pzval, const char* key, double value) |
int add_assoc_double_ex(zval* pzval, const char* key, uint klen, double value) |
int add_assoc_string(zval* pzval, const char* key, const char* value) |
int add_assoc_string_ex(zval* pzval, const char* key, uint klen, const char* value) |
int add_assoc_stringl(zval* pzval, const char* key, const char* value, uint vlen, zend_bool duplicate) |
int add_assoc_stringl_ex(zval* pzval, const char* key, uint klen, const char* value, uint vlen, zend_bool duplicate) |
int add_assoc_zval(zval* pzval, const char* key, zval* value) |
int add_assoc_zval_ex(zval* pzval, const char* key, uint klen, zval* value) |
Note:
add_*_string functions that accept a parameter named duplicate, will duplicate the string with
estrndup
whenduplicate
is true
Note:
add_*_zval functions do not adjust the refcount of the
value
parameter
To perform more advanced operations on array variables we must use the HashTable API directly.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-internals2.variables.arrays.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.