php扩展开发之数组初始化及赋值
发布时间:2022-09-28 18:27:32 230
相关标签: # php
扩展中的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测试代码:
输出结果:
[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)
}
文章来源: https://blog.51cto.com/u_13646572/5361223
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报