返回

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测试代码:


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)
}


特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
PHP扩展开发之计算两个数的和 2022-09-28 17:34:12