如何修复警告非法串在PHP偏移 [英] How to fix Warning Illegal string offset in PHP

查看:167
本文介绍了如何修复警告非法串在PHP偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP code的这个块是给我的错误:

I have this chunk of PHP code which is giving me the error:

警告:非法字符串偏移iso_format_recent_works在
   C:\\ XAMPP \\ htdocs中\\曼塔\\可湿性粉剂内容\\ \\主题曼塔\\的functions.php 标签上
  行 1328

Warning: Illegal string offset 'iso_format_recent_works' in C:\xampp\htdocs\Manta\wp-content\themes\manta\functions.php on line 1328

这是一个警告是与在code:

This is the code that the warning is relating to:

if(1 == $manta_option['iso_format_recent_works']){
    $theme_img = 'recent_works_thumbnail';
} else {
    $theme_img = 'recent_works_iso_thumbnail';
}

当我做一个一个的var_dump($ manta_option);我收到如下的结果:

When I do an a var_dump($manta_option); I receive the follow result:

[iso_format_recent_works] =>串(1)1

["iso_format_recent_works"]=> string(1) "1"

我已经试过铸造$ manta_option ['iso_format_recent_works']为int,但仍然得到了同样的问题。

I have tried casting $manta_option['iso_format_recent_works'] to an int but still get the same issue.

任何帮助将大大AP preciated。

Any help would be greatly appreciated.

推荐答案

魔语是:使用isset

验证条目:

if(isset($manta_option['iso_format_recent_works']) && $manta_option['iso_format_recent_works'] == 1){
    $theme_img = 'recent_works_thumbnail';
} else {
    $theme_img = 'recent_works_iso_thumbnail';
}

这篇关于如何修复警告非法串在PHP偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆