你可以做的是直接传递给你的函数。你的函数应该是这样的,如果一个变量名被传递给它,它应该是该变量的值,否则是一个包含所有变量值的数组。
你可以做到这一点是:
<?php
// pass your variable to the function getResponseInfo, for which you want the value.
echo $var->getResponse()->getResponseInfo('http_code');
?>
您的功能:
<?php
// by default, it returns an array of all variables. If a variable name is passed, it returns just that value.
function getResponseInfo($var=null) {
// create your array as usual. let's assume it's $result
/*
$result = array('http_code'=>200,'http_status'=>'ok','content_length'=>1589);
*/
if(isset($var) && array_key_exists($var, $result)) {
return $result[ $var ];
} else {
return $result;
}
}
?>
希望它能帮助。
应该是好的,虽然我不知道调用“两个”方法; $ var-> getResponse() - > getResponseInfo ..不应该那些理想地分开? – Bono 2012-04-17 11:18:49
我问了同样的问题,它被关闭为http://stackoverflow.com/questions/2396782/parse-error-on-explode-foo-bar0-for-instance :( – 2012-04-17 11:27:40