|
发表于 2015-1-19 15:36:28
|
显示全部楼层
不知道是不是你要的。
PHP复制代码
class Welcome extends CI_Controller {
public function index () {
$variable = array(
'a' => '1',
'b' => '2',
'c' => '3',
'd' => '4',
);
$this->load->library('text'); //第一次可行,第二次就失败
foreach ($variable as $key => $value) {
$data = array('key' => $key, 'value' => $value);
$this->text->init($data);
$temp = $this->text->function1();
if($temp){
var_dump($data);
break;
}
}
}
}
复制代码PHP复制代码
class Text {
private $key;
private $value;
public function __construct ($data='') {
$this->init($data);
}
function init ($data){
if(!$data) return;
$this->key = $data["key"];
$this->value = $data["value"];
echo $this->key . "<br/>";
echo $this->value . "<br/>";
}
public function function1 () {
$key = $this->key;
$value = $this->value;
if($key == "d" && $value == "4") {
return TRUE;
} else {
return FALSE;
}
}
}
复制代码
输出:
a
1
b
2
c
3
d
4
array 'key' => string 'd' (length=1) 'value' => string '4' (length=1)
|
评分
-
查看全部评分
|