简体   繁体   English

试图拆分数组。 工作但显示错误

[英]Trying to split array. Working but showing error

I want to split an array in php with explode. 我想用php拆分数组。 My array looks likes this: 我的数组看起来像这样:

C:\wamp64\www\SC New Skin\functions\get\userItems.php:21:
array (size=1)
  0 => 
    array (size=6)
      0 => 
        array (size=0)
          empty
      1 => string '1,1' (length=3)
      2 => string '2,11' (length=4)
      4 => string '1,8' (length=3)
      5 => string '2,10' (length=4)
      8 => string '1,6' (length=3)

I want to split on the ",". 我想分割“,”。

My code looks like this: 我的代码如下所示:

function getItems($array){
    $array = array_unique($array);
    foreach ($array as $key) {
        $var = explode(",", $key);
        echo $var[0];
        echo $var[1] . '<br/>';
    }
}

This will work but gives two errors: 这将起作用,但是会出现两个错误:

Notice: Array to string conversion in C:\\wamp64\\www\\SC New Skin\\functions\\get\\userItems.php on line 20 & Warning: explode() expects parameter 2 to be string, array given in C:\\wamp64\\www\\SC New Skin\\functions\\get\\userItems.php on line 22 注意:第20行的C:\\ wamp64 \\ www \\ SC New Skin \\ functions \\ get \\ userItems.php中的数组到字符串的转换警告:explode()期望参数2为字符串,数组在C:\\ wamp64 \\ www中给出第22行的\\ SC New Skin \\ functions \\ get \\ userItems.php

This may be because the first element of the internal array is also an array, not a string like the other elements: 这可能是因为内部数组的第一个元素也是一个数组,而不是像其他元素一样的字符串:

0 => 
   array (size=0)
        empty

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM