PHP_FUNCTION(my_func) {
array_init(return_value);
add_index_long(return_value, 0, 123);
}
Call your function from a PHP script like this:
$arr = my_func( ); // $arr[0] holds 123
To add a string element to the array:
add_index_string(return_value, 1, "thestring", 1);
This would result in:
$arr[1] = "thestring"
If you have a static string whose length you know already, use the
add_index_stringl( ) function:
add_index_stringl(return_value, 1, "abc", 3, 1);
The final argument specifies whether or not the string you provide
should be copied. Normally, you would set this to 1. The only time
you wouldn't is when you have allocated the memory
for the string yourself, using one of PHP's
emalloc( )-like functions. For example:
char *str;
str = estrdup("abc");
add_index_stringl(return_value, 1, str, 3, 0);
Inserting at a specific numeric index ($arg[$idx] =
$value) looks like this:
add_index_long(zval *arg, uint idx, long n)
add_index_null(zval *arg, uint idx)
add_index_bool(zval *arg, uint idx, int b)
add_index_resource(zval *arg, uint idx, int r)
add_index_double(zval *arg, uint idx, double d)
add_index_string(zval *arg, uint idx, char *str, int duplicate)
add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate)
add_index_zval(zval *arg, uint index, zval *value)
Inserting at the next numeric index ($arg[] =
$value) looks like this:
add_next_index_long(zval *arg, long n)
add_next_index_null(zval *arg)
add_next_index_bool(zval *, int b)
add_next_index_resource(zval *arg, int r)
add_next_index_double(zval *arg, double d)
add_next_index_string(zval *arg, char *str, int duplicate)
add_next_index_stringl(zval *arg, char *str, uint length, int duplicate)
add_next_index_zval(zval *arg, zval *value)
And inserting at a specific string index ($arg[$key] =
$value) looks like this:
add_assoc_long(zval *arg, char *key, long n)
add_assoc_null(zval *arg, char *key)
add_assoc_bool(zval *arg, char *key, int b)
add_assoc_resource(zval *arg, char *key, int r)
add_assoc_double(zval *arg, char *key, double d)
add_assoc_string(zval *arg, char *key, char *str, int duplicate)
add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate)
add_assoc_zval(zval *arg, char *key, zval *value)