嘗試使用陣列偏移量存取空類型值
P粉334721359
P粉334721359 2023-08-25 09:40:08
0
1
622
<p>我有一個php機器人(在IRC上),自從我將php和mysql更新到CentOS的最新版本後,我遇到了這個錯誤</p> <pre class="brush:php;toolbar:false;">unset($ops_activos); unset($voices_activos); if ($on_pthelp == 1) { if ($ops["#pthelp"]['count'] > 0) { foreach ($ops["#pthelp"] as $value) { if (!is_int($value)) { if (isset($ops_activos)) { $ops_activos .= " " . $value; } else { $ops_activos = $value; } } } if ($bot_debug) { scmd("PRIVMSG ". $log_chan ." :[Membros (Mode)] [OPS]: ". $ops_activos); } } unset ($value); if ($voices["#pthelp"]['count'] > 0) { foreach ($voices["#pthelp"] as $value) { if (!is_int($value)) { if (isset($voices_activos)) { $voices_activos .= " " . $value; } else { $voices_activos = $value; } } } if ($bot_debug) { scmd("PRIVMSG ". $log_chan ." :[Membros (Mode)] [VOICES]: ". $voices_activos); } }</pre> <p>錯誤所在行</p> <pre class="brush:php;toolbar:false;">if ($ops["#pthelp"]['count'] > 0) {</pre></p>
P粉334721359
P粉334721359

全部回覆(1)
P粉268654873

在比較之前,您需要檢查數組中是否存在您擁有的鍵,因為無論如何它都找不到它。

請改用以下程式碼:

if (isset($ops["#pthelp"]['count']) && $ops["#pthelp"]['count']> 0)

此外,這樣做可以避免任何進一步的問題。

if (isset($voices["#pthelp"]['count']) &&  $voices["#pthelp"]['count'] > 0)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板