扩展中的C语言代码

PHP_FUNCTION(hello_array){
char *mystr;
zval *mysubarray;
array_init(return_value); //初始化一个新数组
add_index_long(return_value, 42, 123);//向数字索引的数组增加指定类型的值
add_next_index_string(return_value, "I should now be found at index 43");
add_next_index_stringl(return_value, "I'm at 44!", 10);
mystr = estrdup("Forty Five");
add_next_index_string(return_value, mystr);
add_assoc_double(return_value, "pi", 3.1415926535);
}

php测试代码:

<?php
var_dump(hello_array());

输出结果:

[root@localhost hello]# php /root/php/hello.php
array(5) {
[42]=>
int(123)
[43]=>
string(33) "I should now be found at index 43"
[44]=>
string(10) "I'm at 44!"
[45]=>
string(10) "Forty Five"
["pi"]=>
float(3.1415926535)
}