我不明白为什么这段代码会给php 5.4发出警告?我该如何解决这个问题?
function load(){
for ($i = 0, $n = sizeof($messages); $i < $n; $i++){
$this->add($messages[$i]['field'], $messages[$i]['type']);
}
}
function add($field, $type){
$this->messages[] = array('field' => $field, 'type' => $type);
}
答案 0 :(得分:1)
试试这个
function load(){
for ($i = 0, $n = sizeof($messages); $i < $n; $i++){
if(isset($messages[$i]['field']) && isset($messages[$i] ['field'])){
$this->add($messages[$i]['field'], $messages[$i]['type']);
}
}
}
function add($field, $type){
$this->messages[] = array('field' => $field, 'type' => $type);
}