通过表单操作POST从数组中获取特定值

时间:2014-04-30 23:26:56

标签: php arrays multidimensional-array

我无法从数组中获取特定值。我试过这个,但它不起作用。

                $item1 = $this->request->post['banner_image'];

        foreach($item1 as $k => $v) 
                    {
                      if($k == 'top' && $v > 0) 
                      {
                       echo $v.' - ';
                      }
                    }

我只需要获得一些值...例如我们[top]和[left]。

这是var_dump($ _ POST);

array(2) {
  ["pavcontentslider_module"]=>
  array(1) {
    [0]=>
    array(11) {
      ["layout_id"]=>
      string(1) "1"
      ["position"]=>
      string(9) "slideshow"
      ["status"]=>
      string(1) "1"
      ["sort_order"]=>
      string(1) "1"
      ["auto_play"]=>
      string(1) "0"
      ["text_interval"]=>
      string(4) "8000"
      ["width"]=>
      string(4) "1170"
      ["height"]=>
      string(3) "540"
      ["image_navigator"]=>
      string(1) "1"
      ["navimg_weight"]=>
      string(3) "184"
      ["navimg_height"]=>
      string(2) "81"
    }
  }
  ["banner_image"]=>
  array(6) {
    [1]=>
    array(7) {
      ["image"]=>
      string(26) "data/slider/imgslider3.jpg"
      ["link"]=>
      string(0) ""
      ["title"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(5) "testo"
        }
        [1]=>
        array(1) {
          [0]=>
          string(8) "engtesto"
        }
      }
      ["effect"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(7) "tossing"
        }
        [1]=>
        array(1) {
          [0]=>
          string(6) "bounce"
        }
      }
      ["class"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(12) "banner-info1"
        }
        [1]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
      }
      ["top"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "90"
        }
        [1]=>
        array(1) {
          [0]=>
          string(3) "160"
        }
      }
      ["left"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(3) "660"
        }
        [1]=>
        array(1) {
          [0]=>
          string(3) "335"
        }
      }
    }
    [2]=>
    array(7) {
      ["image"]=>
      string(26) "data/slider/imgslider7.jpg"
      ["link"]=>
      string(0) ""
      ["title"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(5) "test2"
        }
        [1]=>
        array(1) {
          [0]=>
          string(8) "engtest2"
        }
      }
      ["effect"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
        [1]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
      }
      ["class"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(12) "banner-info1"
        }
        [1]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
      }
      ["top"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "91"
        }
        [1]=>
        array(1) {
          [0]=>
          string(3) "183"
        }
      }
      ["left"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(3) "210"
        }
        [1]=>
        array(1) {
          [0]=>
          string(3) "432"
        }
      }
    }
    [3]=>
    array(7) {
      ["image"]=>
      string(26) "data/slider/imgslider5.jpg"
      ["link"]=>
      string(0) ""
      ["title"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(5) "testo"
        }
        [1]=>
        array(1) {
          [0]=>
          string(7) "resrser"
        }
      }
      ["effect"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
        [1]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
      }
      ["class"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
        [1]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
      }
      ["top"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "10"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "29"
        }
      }
      ["left"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "20"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "66"
        }
      }
    }
    [4]=>
    array(7) {
      ["image"]=>
      string(26) "data/slider/imgslider6.jpg"
      ["link"]=>
      string(0) ""
      ["title"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(5) "testo"
        }
        [1]=>
        array(1) {
          [0]=>
          string(4) "teso"
        }
      }
      ["effect"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
        [1]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
      }
      ["class"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
        [1]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
      }
      ["top"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "27"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "22"
        }
      }
      ["left"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "61"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "66"
        }
      }
    }
    [5]=>
    array(7) {
      ["image"]=>
      string(26) "data/slider/imgslider8.jpg"
      ["link"]=>
      string(0) ""
      ["title"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(5) "testo"
        }
        [1]=>
        array(1) {
          [0]=>
          string(6) "tes6yo"
        }
      }
      ["effect"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
        [1]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
      }
      ["class"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
        [1]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
      }
      ["top"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "20"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "14"
        }
      }
      ["left"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "38"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "57"
        }
      }
    }
    [6]=>
    array(7) {
      ["image"]=>
      string(26) "data/slider/imgslider2.jpg"
      ["link"]=>
      string(0) ""
      ["title"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(5) "testo"
        }
        [1]=>
        array(1) {
          [0]=>
          string(5) "testo"
        }
      }
      ["effect"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
        [1]=>
        array(1) {
          [0]=>
          string(7) "slideUp"
        }
      }
      ["class"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
        [1]=>
        array(1) {
          [0]=>
          string(11) "banner-info"
        }
      }
      ["top"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "29"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "25"
        }
      }
      ["left"]=>
      array(2) {
        [4]=>
        array(1) {
          [0]=>
          string(2) "66"
        }
        [1]=>
        array(1) {
          [0]=>
          string(2) "47"
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

更好地查看结果的方法是在var_dump之前先echo "<pre>";。这将允许您更好地了解数组的格式。我的猜测是,您正在搜索的$key是嵌入在更深层次的。如果您仍然无法解析它,请尝试编辑您的帖子,以便我们查看更好的格式化视图。很难看到,但尝试回显(没有for循环)$item1[1]['image']并查看是否有任何东西吐出来。我认为您感兴趣的值实际上在$item1[1]之内,而不仅仅是$item1。希望这是有道理的。