Re: associative arrays

From: Date: Mon, 13 Aug 2001 14:00:16 +0000
Subject: Re: associative arrays
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-63079@lists.php.net to get a copy of this message
On Mon, 13 Aug 2001, Rasmus Lerdorf wrote: > Ah, ok. It's not much harder: > > pval *tmp_arr; > > array_init(return_value); > MAKE_STD_ZVAL(tmp_arr); > array_init(tmp_arr); > add_assoc_string(tmp_arr, "string index", "foo", 1); > zend_hash_index_update(Z_ARRVAL_P(return_value), 5, &tmp_arr, sizeof(tmp_arr), NULL); > > This will create $whatever[5]['string index'] = 'foo' > > Or if you want a string index at the top level: > > zend_hash_update(Z_ARRVAL_P(return_value), "bar", strlen("bar")+1, > &tmp_arr, sizeof(tmp_arr), NULL); > > This will create $whatever['bar']['string index'] = 'foo'; There is add_assoc_zval().. -Andrei Computer, if you don't open that exit hatch this moment I shall zap straight off to your major data banks and reprogram you with a very large axe. -- Douglas Adams / The Hitchhiker's Guide to the Galaxy

« previous php.dev (#63079) next »