So for this to not be to confusing, I have:
A) [add_to_array] function that feeds in the contents of an array and then returns the array with an additional element.
So far so good. This works fine. Then I have:
B) [get_array_info] Function that takes in an array, iterates through it, builds another array and returns that.
Here is the problem. In PHP the activity looks like this:
Code: Select all
$stuff_to_add = array("test"=>"info","test2"=>"info2");
$data = add_to_array($stuff_to_add,$data);
print_r(get_array_info($data));Code: Select all
PHP_FUNCTION(add_to_array)
{
//omitted
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa",&arr,&arr2) == FAILURE)
RETURN_FALSE;
//omitted
while(zend_hash_get_current_data(arr->value.ht, (void **)&data) == SUCCESS) {
// get data from stuff_to_add
zend_hash_move_forward(arr->value.ht);
}
while(zend_hash_get_current_data(arr2->value.ht, (void **)&data) == SUCCESS) {
// do the additions to the array here
zend_hash_move_forward(arr2->value.ht);
}
//omitted stuff
*return_value = *arr2;
zval_copy_ctor(return_value);
}
PHP_FUNCTION(get_array_info)
{
//omitted
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a",&arr) == FAILURE)
RETURN_FALSE;
//omitted stuff
zend_hash_internal_pointer_reset(arr->value.ht);
while(zend_hash_get_current_data(arr->value.ht, (void **)&data) == SUCCESS) {
//iterate through arr and build new array (return_value) for ouput
zend_hash_move_forward(sess->value.ht);
}
//omitted stuff
}I have also tried this by replacing $data with $_SESSION so I have a persistant value in the array. If I don't "add_to_array" the "get_array_info" displays the correct information. The problem has something to do with iterating through the array once, and then trying to do so again. But that is why I thought the zend_hash_internal_pointer_reset() function would solve the problem. It didn't.
Any thoughts? Do I need to explain anything more clearly?