免费邮箱 |加入收藏 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > PHP专区 > PHP技巧

引用的解释

时间:2011-05-16 15:55:22  来源:站内  作者:潘春会

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.

gunter dot sammet at gmail dot com (09-Aug-2006 04:23)

 

 

 

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!

Xor (02-Mar-2006 11:43)

 

 

 

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);
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
如何找出DHCP地址池里未使用的IP地址
如何找出DHCP地址池里
国内常用的DNS列表
国内常用的DNS列表
Linux邮件服务器软件比较
Linux邮件服务器软件比
学用纯CSS打造可折叠树状菜单
学用纯CSS打造可折叠树
相关文章
栏目更新
栏目热门