Different between add_assoc_zval() and add_assoc_string()
| From: | 羊生杰 | Date: | Fri, 31 Jan 2014 07:54:59 +0000 |
| Subject: | Different between add_assoc_zval() and add_assoc_string() | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-11478@lists.php.net to get a copy of this message | ||
Hi everyoneI am writing a function which can save the value of arguments, for example:
print_r(config("a",array("sub"=>"baidu")));
print_r(config("b",array("sub"=>"google")));
I want to get the result as below:
Array
(
[a] => Array
(
[sub] => baidu
)
)
Array
(
[a] => Array
(
[sub] => baidu
)
[b] => Array
(
[sub] => google
)
)
I use add_assoc_string() when the argument is string,and it works fine,but when the argument is a
array,and i use
add_assoc_zval(),the result is not what i want.
here is my code:
if(Z_TYPE_P(value) == IS_STRING){
add_assoc_string(config, key, Z_STRVAL_P(value), 1);
RETURN_ZVAL(config, 1, 0);
return;
}else if(Z_TYPE_P(value) == IS_ARRAY){
add_assoc_zval(config, key, value);
RETURN_ZVAL(config, 1, 0);
return;
}
what could the problem be?