0

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

较大的数组有多个“段”数组,在 var_dump 中,您可以看到数组 (5)。

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

这是数组:Json:

{ "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" } ] } } } }

大批:

    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"
          }
        }
      }
    }

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

编辑:

我要问的是,为什么它在较小的数组中,只有一个“段”数组,我数了一下,显示为 3。它显示了“注释”、“类型”和数组“规则”都是“段”的孩子。现在在更大的数组中,有超过 1 个“segment”行,计数为 5,每个“segment”都有一个包含“comments”、“type”和数组“rules”的数组,而不是直接子代。

4

0 回答 0