php解析数组值

php解析数组值,php,arrays,parsing,Php,Arrays,Parsing,我不太擅长数组,所以这里可能有一些非常简单但不适合我的东西!我通过POST获得一个值数组,我需要解析它们并将值存储在一个表中。我应该如何使用经典解析,例如: foreach($array as $a) { $text = $a->text; $name = $a->user->name; } etc解析如下所示的数组: [item] => Array ( [tags] => Array

我不太擅长数组,所以这里可能有一些非常简单但不适合我的东西!我通过POST获得一个值数组,我需要解析它们并将值存储在一个表中。我应该如何使用经典解析,例如:

foreach($array as $a) {
  $text = $a->text;
  $name = $a->user->name;
}
etc解析如下所示的数组:

[item] => Array
        (
            [tags] => Array
                (
                    [0] => Bluetooth
                    [1] => WiFi
                    [2] => USB
                )

        )

This is the entire POST array:

Array
(
    [prodid] => 
    [Submit] => Save
    [productcode] => 797987
    [cat_id] => 66
    [brand] => Fysiomed
    [name] =>  asdc asdc asd c
    [productnew] => yes
    [item] => Array
        (
            [tags] => Array
                (
                    [0] => Bluetooth
                    [1] => WiFi
                    [2] => USB
                )

        )

    [size] => 1
    [barcode] => 7979871
    [price] => 233.00
    [priceoffer] => 0.00
    [stock] => 50
    [weight] => 0.30
    [orderby] => 1
)

你只是想把文字说出来吗?试试这个

foreach($array['item']['tags'] as $tag) {
   $text = $tag;
}
if(isset($\u POST)和&!empty($\u POST)){
foreach($\发布为$key=>$value){
如果($key=='item'){
回显$value[$key]['tag'][0]。
; 回显$value[$key]['tag'][1]。
; 回显$value[$key]['tag'][2]。
; } } }
看起来您的数组的形状是这样的,请检查此项

$array = array( "item" => array( "tags" => array("Bluetooth", "Wifi", "USB" ) ) );
var_dump($array);
你会看到像这样的东西

array(1) {
  ["item"]=>
  array(1) {
    ["tags"]=>
    array(3) {
      [0]=>
      string(9) "Bluetooth"
      [1]=>
      string(4) "Wifi"
      [2]=>
      string(3) "USB"
    }
  }
}
现在要分析这个数组

foreach($array as $in => $val) {
    // as $array has key=>value pairs, only one key value pair
    // here $in will have the key and $val will have the value
    // $in will be "item"
    print $in; // this will print "item"
    foreach($val as $in2 => $val2 ){
        // only one key : "tags"
        print $in; // this will print "tags"
        print $val2[0];  // this will print "Bluetooth"
        print $val2[1];  // this will print "Wifi"
    } 
}

我希望这可以消除您对数组的疑虑。

您能告诉我们您的POST输入是什么吗?您的POST数组看起来如何?POST数组添加到了第1篇文章中。您想做什么还不清楚。不能将多维数组放入二维表中。您需要展开一点。我需要将所有标记作为字符串获取,并将它们添加到我的数据库中的表中。这会输出以下警告:为foreach()提供的无效参数“tag”应该是“tags”,我认为。您必须用调用数组的任何内容替换数组$_也许是发帖吧。你不必反复浏览整个$u POST arrayNo。谢谢你的勾选:)我将以这个为例来尝试更多地理解它们。非常感谢。
array(1) {
  ["item"]=>
  array(1) {
    ["tags"]=>
    array(3) {
      [0]=>
      string(9) "Bluetooth"
      [1]=>
      string(4) "Wifi"
      [2]=>
      string(3) "USB"
    }
  }
}
foreach($array as $in => $val) {
    // as $array has key=>value pairs, only one key value pair
    // here $in will have the key and $val will have the value
    // $in will be "item"
    print $in; // this will print "item"
    foreach($val as $in2 => $val2 ){
        // only one key : "tags"
        print $in; // this will print "tags"
        print $val2[0];  // this will print "Bluetooth"
        print $val2[1];  // this will print "Wifi"
    } 
}