Re: how-to get array[0] and array["name"] to actually reference only 1 value?

From: Date: Mon, 12 Feb 2001 10:31:02 +0000
Subject: Re: how-to get array[0] and array["name"] to actually reference only 1 value?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-46416@lists.php.net to get a copy of this message
Well, I guess that hacking the php source would work. :) However, I was just thinking that you Could do something like this: (Note - not tested! :) while (list ($key, $value) = mysql_fetch_array ($result, MYSQL_ASSOC)) { $data[] =& $data[$key] = $value; } --zak ----- Original Message ----- From: "Marc Boeren" <M.Boeren@guidance.nl> To: "'Zak Greant'" <zak@nucleus.com> Cc: <php-dev@lists.php.net> Sent: Monday, February 12, 2001 2:25 AM Subject: RE: [PHP-DEV] how-to get array[0] and array["name"] to actually reference only 1 value? > > >not bound together in any way. You may be able to accomplish what you > >desire by using references. (See the manual section on references for more > >information. > > > ie. $q->data[0]["id"] =& $q->data[0][0]; > > After looking for references in the php-code, I found something that seems > to work ok (zend_assign_to_variable_reference): > > zval *dummy, *value, **x_ptr, **y_ptr; > MAKE_STD_ZVAL(value); > ZVAL_LONG(value, 10); > ALLOC_ZVAL(dummy); > INIT_ZVAL(*dummy); > zend_hash_update(return_value->value.obj.properties, "x", > sizeof("x"), > &value, sizeof(zval *), (void **) &x_ptr); > zend_hash_update(return_value->value.obj.properties, "y", > sizeof("y"), > &dummy, sizeof(zval *), (void **) &y_ptr); > zend_assign_to_variable_reference(NULL, y_ptr, x_ptr, NULL ELS_CC); > > This leads me to another question: how do I obtain the x_ptr (from the > example) if the zend_hash_update was done elsewhere and no ptr was passed > then??? > > zend_hash_update(return_value->value.obj.properties, "x", > sizeof("x"), > &value, sizeof(zval *), NULL); > [...] > // How do I get the x_ptr ??? > zend_hash_update(return_value->value.obj.properties, "y", > sizeof("y"), > &dummy, sizeof(zval *), (void **) &y_ptr); > zend_assign_to_variable_reference(NULL, y_ptr, x_ptr, NULL ELS_CC); > > Cheerio, Marc.

« previous php.dev (#46416) next »