Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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_Mysql - Fatal编程技术网

PHP关联子数组

PHP关联子数组,php,mysql,Php,Mysql,我的数组如下所示:如何显示消息值和任意键 ( [@@warning_count] => 2 [0] => Array ( [Level] => Warning [Code] => 1366 [Message] => Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1 ) [1] => Array

我的数组如下所示:如何显示消息值和任意键

(
   [@@warning_count] => 2

    [0] => Array
    (
      [Level] => Warning
      [Code] => 1366
      [Message] => Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1
    )

   [1] => Array
   (
     [Level] => Error
     [Code] => 1062
     [Message] => Duplicate entry ‘peace′ for key ‘groupname’
    )

)

请尝试下面的代码

<?php

$my_array = array   ('@@warning_count' => 2,
            0 => Array  (
              'Level' => 'Warning',
              'Code' => '1366',
              'Message' => 'Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1',
            ),
         1 => Array(
             'Level' => 'Error',
             'Code' => '1062',
             'Message' => 'Duplicate entry ‘peace′ for key ‘groupname’',
            ),
);


foreach ($my_array as $arr_key => $arr_val){

    if(is_array($arr_val) == true ){
        echo $arr_val['Message'];
    }
}

?>


让我知道以上代码…

这就是您想要实现的结果吗

<?php
    $dataArray = Array(
        array(
            'Level' => 'Warning',
            'Code' => '1366',
            'Message' => 'Message here 1',
            ),

            array(
            'Level' => 'Warning',
            'Code' => '1062',
            'Message' => 'Message here 2',
            ),

            array(
            'Level' => 'Warning',
            'Code' => '3233',
            'Message' => 'Message here 3',
            )

    );

    // This shows the whole array: 
    echo '<pre>';
    var_dump($dataArray);
    echo '</pre>';


    // Select only the messages: 
    foreach ($dataArray as $key => $value) {
        echo $value['Message'].'<br />';
    }
?>

我想你想要这样的东西。参考:


你尝试了什么?,似乎是你的家庭作业……谢谢@Mandip Darji it works谢谢@Bubba这很有效,有助于我理解如何处理arrayThanks,以获得每个人的响应。
<?php

$my_array = array   ('@@warning_count' => 2,
            0 => Array  (
              'Level' => 'Warning',
              'Code' => '1366',
              'Message' => 'Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1',
            ),
         1 => Array(
             'Level' => 'Error',
             'Code' => '1062',
             'Message' => 'Duplicate entry ‘peace′ for key ‘groupname’',
            ),
);


foreach ($my_array as $arr_key => $arr_val){

    if(is_array($arr_val) == true ){
        echo $arr_val['Message'];
    }
}

?>
<?php
    $dataArray = Array(
        array(
            'Level' => 'Warning',
            'Code' => '1366',
            'Message' => 'Message here 1',
            ),

            array(
            'Level' => 'Warning',
            'Code' => '1062',
            'Message' => 'Message here 2',
            ),

            array(
            'Level' => 'Warning',
            'Code' => '3233',
            'Message' => 'Message here 3',
            )

    );

    // This shows the whole array: 
    echo '<pre>';
    var_dump($dataArray);
    echo '</pre>';


    // Select only the messages: 
    foreach ($dataArray as $key => $value) {
        echo $value['Message'].'<br />';
    }
?>
<?php
$myArray = array(
      '@@warning_count' => 2,
      array(
          'level' => 'Warning',
          'code' => 1266,
          'message' => "Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1"),
      array(
          'level' => 'Warning',
          'code' => 1266,
          'message' => "Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1"),
);

print "Warning Count: {$myArray['@@warning_count']}\n";
print "------------------\n\n";
foreach ($myArray as $key => $value){
    if (is_array($value)){
        foreach ($value as $subKey => $subValue){
            print $subKey . "=>" . $subValue . "\n";
        }
        print "------------------\n";
    }
}