Home  >  Article  >  Backend Development  >  自定义函数参数是数组,该怎么解决

自定义函数参数是数组,该怎么解决

WBOY
WBOYOriginal
2016-06-13 13:11:491415browse

自定义函数参数是数组
就是那个参数是数组

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->function isNothing($a){
    
    echo $a[1];
    for($i=0;$i<count echo>";
    }
}
</count>

由于$a我传的是一个数组,故会报错
Notice: Undefined offset: 1 in D:\xampp\htdocs\index.php on line 14

请问参数是数组时怎么办?
不要说用global。因为数组不定

------解决方案--------------------
传递数组没有下标为1的元素
------解决方案--------------------
不知道你要达到什么目的
或许这样符合你的要求
PHP code
function isNothing($a){
  if(count($a) ";
  }
}
<br><font color="#e78608">------解决方案--------------------</font><br>数组的下标不存在,用个翻译软件翻译一下就能明白了
<br><font color="#e78608">------解决方案--------------------</font><br> echo $a[1];<br>下面还有个<br>  echo $a[2];<br>结果您的$a只有一个元素,于是悲剧了
<br><font color="#e78608">------解决方案--------------------</font><br>var_dump($a);<br>先看看$a是什么样的格式。<br>if(is_array($a))<br>{<br>$a = $a[0];//最起码是数组肯定有下标0的<br>}
<br><font color="#e78608">------解决方案--------------------</font><br>楼上说的不对,非序列的php数组是可以没有下标0的 <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn