Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么具有一个数组的多维数组与具有多个数组的多维数组不同?_Php_Arrays_Json_Multidimensional Array - Fatal编程技术网

Php 为什么具有一个数组的多维数组与具有多个数组的多维数组不同?

Php 为什么具有一个数组的多维数组与具有多个数组的多维数组不同?,php,arrays,json,multidimensional-array,Php,Arrays,Json,Multidimensional Array,我不确定我的措辞是否正确,但基本上,我有两个数组(见下文)。第一个数组只有一个“段”数组,但在执行var_转储时,它会显示它的子数组(或者根本不显示) 较大的数组有多个“段”数组,在var_转储中,可以看到数组(5) 背景是我从用php解码的json字符串中获取这两个数组 以下是阵列: Json: 数组: array(1) { ["css"]=> array(1) { ["segment"]=> array(3) { ["type"]=&g

我不确定我的措辞是否正确,但基本上,我有两个数组(见下文)。第一个数组只有一个“段”数组,但在执行var_转储时,它会显示它的子数组(或者根本不显示)

较大的数组有多个“段”数组,在var_转储中,可以看到数组(5)

背景是我从用php解码的json字符串中获取这两个数组

以下是阵列: Json:

数组:

    array(1) {
  ["css"]=>
  array(1) {
    ["segment"]=>
    array(3) {
      ["type"]=>
      string(4) "Body"
      ["comments"]=>
      string(23) " v4 theme.css"
      ["rule"]=>
      array(2) {
        ["selector"]=>
        string(4) "html"
        ["declaration"]=>
        array(4) {
          [0]=>
          array(2) {
            ["property"]=>
            string(6) "margin"
            ["value"]=>
            string(1) "0"
          }
          [1]=>
          array(2) {
            ["property"]=>
            string(7) "padding"
            ["value"]=>
            string(1) "0"
          }
          [2]=>
          array(2) {
            ["property"]=>
            string(6) "height"
            ["value"]=>
            string(4) "100%"
          }
          [3]=>
          array(2) {
            ["property"]=>
            string(10) "background"
            ["value"]=>
            string(34) "#fff url(body_bg.gif) repeat-x top"
          }
        }
      }
    }
  }
}
Json:

排列

我的问题是,当“段”中只有1个数组时,如何强制执行数组,或者为什么会发生这种情况

编辑:


我要问的是,为什么它在较小的数组中,只有一个“段”数组,我对它进行计数,如图3所示。它显示“注释”、“类型”和数组“规则”,它们都是“段”的子级。现在,在更大的数组中,有超过1个“段”行,计数为5,每个“段”都有一个带有“注释”、“类型”和数组“规则”的数组,而不是直接子数组。

您可以共享json字符串吗?您可以发布您收到的json字符串吗?@JayD。您的
JSON
在值中包含值,因此它创建了一个
多维数组
@JayD。每件事都完全按照它应该的那样工作。var_dump以这种方式表示数组,因为这就是json字符串的含义。我认为您误解了var_dump值。它表示有一个具有5个类型值的段,而不是5个段。
    array(1) {
  ["css"]=>
  array(1) {
    ["segment"]=>
    array(3) {
      ["type"]=>
      string(4) "Body"
      ["comments"]=>
      string(23) " v4 theme.css"
      ["rule"]=>
      array(2) {
        ["selector"]=>
        string(4) "html"
        ["declaration"]=>
        array(4) {
          [0]=>
          array(2) {
            ["property"]=>
            string(6) "margin"
            ["value"]=>
            string(1) "0"
          }
          [1]=>
          array(2) {
            ["property"]=>
            string(7) "padding"
            ["value"]=>
            string(1) "0"
          }
          [2]=>
          array(2) {
            ["property"]=>
            string(6) "height"
            ["value"]=>
            string(4) "100%"
          }
          [3]=>
          array(2) {
            ["property"]=>
            string(10) "background"
            ["value"]=>
            string(34) "#fff url(body_bg.gif) repeat-x top"
          }
        }
      }
    }
  }
}
{ "css": { "segment": [ { "type": "Body", "comments": "Launch Pad v4 theme.css", "rule": [ { "selector": "html", "declaration": [ { "property": "margin", "value": "0" }, { "property": "padding", "value": "0" }, { "property": "height", "value": "100%" }, { "property": "background", "value": "#fff url(body_bg.gif) repeat-x top" } ] }, { "selector": "body", "declaration": [ { "property": "font", "value": "12px Arial, Helvetica, sans-serif" }, { "property": "line-height", "value": "1.35", "comments": "Specify default line height as a pure number value (no px/em)...adjusting the value as desired. This will allow the line-height to flex depending on what size the user specifies their text within the rich text editor" }, { "property": "color", "value": "#333" } ] } ] }, { "type": "Fonts/Typography", "comments": "Fonts/Typography" }, { "type": "Header" }, { "type": "Content" }, { "type": "Footer" } ] } }
array(1) {
      ["css"]=>
      array(1) {
        ["segment"]=>
        array(5) {
          [0]=>
          array(3) {
            ["type"]=>
            string(4) "Body"
            ["comments"]=>
            string(23) "theme.css"
            ["rule"]=>
            array(2) {
              [0]=>
              array(2) {
                ["selector"]=>
                string(4) "html"
                ["declaration"]=>
                array(4) {
                  [0]=>
                  array(2) {
                    ["property"]=>
                    string(6) "margin"
                    ["value"]=>
                    string(1) "0"
                  }
                  [1]=>
                  array(2) {
                    ["property"]=>
                    string(7) "padding"
                    ["value"]=>
                    string(1) "0"
                  }
                  [2]=>
                  array(2) {
                    ["property"]=>
                    string(6) "height"
                    ["value"]=>
                    string(4) "100%"
                  }
                  [3]=>
                  array(2) {
                    ["property"]=>
                    string(10) "background"
                    ["value"]=>
                    string(34) "#fff url(body_bg.gif) repeat-x top"
                  }
                }
              }
              [1]=>
              array(2) {
                ["selector"]=>
                string(4) "body"
                ["declaration"]=>
                array(3) {
                  [0]=>
                  array(2) {
                    ["property"]=>
                    string(4) "font"
                    ["value"]=>
                    string(33) "12px Arial, Helvetica, sans-serif"
                  }
                  [1]=>
                  array(3) {
                    ["property"]=>
                    string(11) "line-height"
                    ["value"]=>
                    string(4) "1.35"
                    ["comments"]=>
                    string(216) "Specify default line height as a pure number value (no px/em)...adjusting the value as desired. This will allow the line-height to flex depending on what size the user specifies their text within the rich text editor"
                  }
                  [2]=>
                  array(2) {
                    ["property"]=>
                    string(5) "color"
                    ["value"]=>
                    string(4) "#333"
                  }
                }
              }
            }
          }
          [1]=>
          array(2) {
            ["type"]=>
            string(16) "Fonts/Typography"
            ["comments"]=>
            string(16) "Fonts/Typography"
          }
          [2]=>
          array(1) {
            ["type"]=>
            string(6) "Header"
          }
          [3]=>
          array(1) {
            ["type"]=>
            string(7) "Content"
          }
          [4]=>
          array(1) {
            ["type"]=>
            string(6) "Footer"
          }
        }
      }
    }