PHP的通知数组到字符串转换 [英] php notice array to string conversion
本文介绍了PHP的通知数组到字符串转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的函数有错误。
注意:...中的数组到字符串的转换。
Notice: Array to string conversion in....
我想检查阵列的可用性&如果有返回。我已经搜索了,但是我做不到。
Just I wanna check array availability & return if have. I have searched but, I can't do.
这是我的功能:
function if_array_exists($array,$value) {
if(isset($array[$value]) || array_key_exists($value,$array)) {
$result=array();
$result[0]=$value;
return $result;
} else {
return '<!--- no array named as '.$value.' value in ---!>';
}
}
推荐答案
如果您首先要检查它是否是一个实际的数组,否则应该会阻止该通知(因为它将直接跳转到else。
If you check to see if it's an actual array first, that should prevent the notice (because it will skip directly to the else.
function if_array_exists($array,$value) {
if(is_array($array) && (isset($array[$value]) || array_key_exists($value,$array))) {
$result=array();
$result[0]=$value;
return $result;
} else {
return '<!--- no array named as '.$value.' value in ---!>';
}
}
这篇关于PHP的通知数组到字符串转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文