Re: Resource array of arrays (variable at runTime)

From: Date: Sat, 27 Dec 2003 20:08:53 +0000
Subject: Re: Resource array of arrays (variable at runTime)
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-280@lists.php.net to get a copy of this message
Hello, VIVI Arno wrote:
Hello, I try to build an extension for my pleasure. I would like to make a function which return me an array of variable arrays. For example, I would like that the function "myfunction( $line, $col, $DefaultValue)", return me one array of line arrays with col colums. I mean: $array = { [0] => {[0]=>1,[1]=>1,...[col]=>1}
               [1] => {[0]=>1,[1]=>1,...[col]=>1}
               ................................................
             [line] => {[0]=>1,[1]=>1,...[col]=>1}
            }
Actually, I have this : //********************************************************** zval *childAr , *childAr2 , *childAr3, *childAr4; MAKE_STD_ZVAL(childAr); MAKE_STD_ZVAL(childAr2); MAKE_STD_ZVAL(childAr3); MAKE_STD_ZVAL(childAr4); if (array_init (childA) == FAILURE){ php_error (E_ERROR, "Cannot initialize childAr from return_multi"); RETURN_NULL(); } if (array_init (childAr2) == FAILURE){ php_error (E_ERROR, "Cannot initialize childAr2 from return_multi"); RETURN_NULL(); } if (array_init (childAr3) == FAILURE){ php_error (E_ERROR, "Cannot initialize childAr3 from return_multi"); RETURN_NULL(); } if (array_init (childAr4) == FAILURE){ php_error (E_ERROR, "Cannot initialize childAr4 from return_multi"); RETURN_NULL(); } //**********************************************************
You don't need many pointers. ALLOC_ZVAL(MAKE_STD_ZVAL) does memory allocation, and returns *new* zval pointer. You can use "for" or "while" syntax, like this. //---------------------------------------- int i; zval *child_array; array_init(return_value); for (i = 0; i < child_num; i++) {
    MAKE_STD_ZVAL(child_array);
    array_init(child_array);
    /* something do on child array */
    add_next_index_zval(return_value, child_array);
} //----------------------------------------
So, with this, I can only return an array of four arrays maximum. I mean : $array = { [0] => {[0]=>1,[1]=>1,...[col]=>1}
               [1] => {[0]=>1,[1]=>1,...[col]=>1}
               ................................................
               [3] => {[0]=>1,[1]=>1,...[col]=>1}
            }
Is is possible to return an array of variable array ? Thank you to help me, Sincerely, Arnaud.


« previous php.pecl.dev (#280) next »