0

我有一个示例代码:

$text = 'a:3:{s:2:"id";s:18:"nokiainternal_ver1";s:10:"user_agent";s:13:"NokiaInternal";s:9:"fall_back";s:13:"nokia_generic";}';
$text = unserialize($text);
if(isset($text['model_name'])) {
   $text['model_name'] = 'Nokia'; 
}
echo $text['model_name'];
echo $text['user_agent'];

但结果错误Notice: Undefined index: model_name ...如何解决?

4

1 回答 1

2

下面的代码:

if(isset($text['model_name'])) {
   $text['model_name'] = 'Nokia'; 
}

检查是否model_name已设置,如果已设置,请将其设置为“诺基亚”

这意味着您没有设置model_name任何东西的密钥,这会导致您的Undefined index错误。

尝试:

if(!isset($text['model_name'])) {
   $text['model_name'] = 'Nokia'; 
}
于 2012-07-26T03:52:30.693 回答