output {
before:
v1=shared
v2=shared
v3=shared
v4=shared
after:
v1=shared?
v2=shared no more
v3=shared still
v4=shared still
}
http://www.obdev.at/developers/articles/00002.html says there's no such thing as an "object reference" in PHP, but with detaching it becomes possible.
Hopefully detach, or something like it, will become a language construct in the future.
I tried to create an array with n depth using a recursive function passing array references around. So far I haven't had much luck and I couldn't find anything on the web. So I ended up using eval() and it seems to work well:
<?php
foreach(array_keys($this->quantity_array) AS $key){
if($this->quantity_array[$key] > 0){
$combinations = explode('-', $key);
$eval_string = '$eval_array';
foreach(array_keys($combinations) AS $key2){
$option_key_value = explode('_', $combinations[$key2]);
$eval_string .= '['.$option_key_value[0].']['.$option_key_value[1].']';
}
$eval_string .= ' = '.$this->quantity_array[$key].';';
eval($eval_string);
}
}
?>
This produces an n dimensional array that will be available in the $eval_array variable. Hope it helps somebody!
if given little - passing an array by reference slower than by value,
but not if it is necessary to process much data.
function test_ref(&$arr) {
$size = sizeof($arr);
17/24 首页 上一页 15 16 17 18 19 20 下一页 尾页 |