Arrays

 
zval

 
*new_array

 
;

 
MAKE_STD_ZVAL(new_array)

 
;

 
if(array_init(new_array

 
)

 
!=

 
SUCCESS

 
)

 
{

 
/

 
/

 
do

 
error

 
handling

 
here

 
}



If array_init() fails to create a new array, it returns FAILURE .

To add new elements to the array , you can use numerous functions , depending on what you want to do . טבלה 34-1 , טבלה 34-2 and טבלה 34-3 describe these functions .

טבלה 34-1 .

טבלה 34-2 .

טבלה 34-3 .

This is done using zend_hash_update( )( ) for associative arrays (see דוגמה 34-3 ) and zend_hash_index_update( ) for indexed arrays (see דוגמה 34-4 ) :

דוגמה 34-3 .

 
zval

 
*new_array

 
,

 
*new_element

 
;

 
char

 
*key

 
=

 
"element_key"

 
;

 
MAKE_STD_ZVAL(new_array)

 
;

 
MAKE_STD_ZVAL(new_element)

 
;

 
if(array_init(new_array

 
)

 
==

 
FAILURE

 
)

 
{

 
/

 
/

 
do

 
error

 
handling

 
here

 
}

 
ZVAL_LONG(new_element

 
,

 
10)

 
;

 
if(zend_hash_update(new_array

 
-

 
value.ht

 
,

 
key

 
,

 
strlen(key

 
)

 
+

 
1

 
,

 
(void

 
*

 
)

 
new_element

 
,

 
sizeof(zval

 
*)

 
,

 
NULL

 
)

 
==

 
FAILURE

 
)

 
{

 
/

 
/

 
do

 
error

 
handling

 
here

 
}



דוגמה 34-4 .

 
zval

 
*new_array

 
,

 
*new_element

 
;

 
int

 
key

 
=

 
2

 
;

 
MAKE_STD_ZVAL(new_array)

 
;

 
MAKE_STD_ZVAL(new_element)

 
;

 
if(array_init(new_array

 
)

 
==

 
FAILURE

 
)

 
{

 
/

 
/

 
do

 
error

 
handling

 
here

 
}

 
ZVAL_LONG(new_element

 
,

 
10)

 
;

 
if(zend_hash_index_update(new_array

 
-

 
value.ht

 
,

 
key

 
,

 
(void

 
*

 
)

 
new_element

 
,

 
sizeof(zval

 
*)

 
,

 
NULL

 
)

 
==

 
FAILURE

 
)

 
{

 
/

 
/

 
do

 
error

 
handling

 
here

 
}