繁体   English   中英

从另一个数组内的数组中获取所有值

[英]get all values from array inside of another array

我被困在试图从 php 中的数组文件中获取信息。 我能够读取它并转换为 php 数组,但现在我想在表格中打印存储的信息,但总是得到不正确的值。

¿我怎样才能正确检索信息?

大批:

array (
  'enableservice' => true,
  'putaLimit' => 
  array (
    0 => 0,
    1 => 0,
    2 => 0,
    3 => 0,
    4 => 0,
  ),
  'remoteService' => true,
  'Console' => 
  array (
    0 => 
    array (
      'bConsole' => 1,
      'ConsoleReference' => 'help',
      'EnableConsole' => true,
      'ViewPermissions' => 1,
    ),
  ),
  'accountData' => 
  array (
    0 => 
    array (
      'AccountName' => 'CSSName',
      'accountBalance' => 
      array (
        0 => 450440561,
        1 => 278575333,
        2 => 325290889,
        3 => 1838037277,
        4 => 155835317,
      ),
    ),
    1 => 
    array (
      'AccountName' => 'CSSCustomer',
      'accountBalance' => 
      array (
        0 => 5230834,
        1 => 3008402,
        2 => 3008400,
        3 => 3231485,
        4 => 9025200,
      ),
    ),
  ),
)

accountData 是我想显示为数据表或表的数组。 我会很高兴你的帮助

使用 print_r($content) 来展示这一点:

    stdClass Object
(
    [enableservice] => 1
    [putaLimit] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
        )

    [remoteService] => 1
    [Console] => Array
        (
            [0] => stdClass Object
                (
                    [bConsole] => 1
                    [ConsoleReference] => help
                    [EnableConsole] => 1
                    [ViewPermissions] => 1
                )

        )

    [accountData] => Array
        (
            [0] => stdClass Object
                (
                    [AccountName] => CSSName
                    [accountBalance] => Array
                        (
                            [0] => 450440561
                            [1] => 278575333
                            [2] => 325290889
                            [3] => 1838037277
                            [4] => 155835317
                        )

                )

            [1] => stdClass Object
                (
                    [AccountName] => CSSCustomer
                    [accountBalance] => Array
                        (
                            [0] => 5230834
                            [1] => 3008402
                            [2] => 3008400
                            [3] => 3231485
                            [4] => 9025200
                        )

                )

        )

)

我使用了您提供的数组并在下面创建了一个解决方案。 此解决方案不是执行此操作的唯一方法。 但这很容易理解。

您可以进一步阅读该主题并查看官方文档中使用关联 arrays 的其他示例。

这是解决方案的沙盒代码示例链接。

http://sandbox.onlinephpfunctions.com/code/532935a21f5f80d8e6d128bed69be18096093ab2

<?php

$arr = array (
  'enableservice' => true,
  'putaLimit' => 
  array (
    0 => 0,
    1 => 0,
    2 => 0,
    3 => 0,
    4 => 0,
  ),
  'remoteService' => true,
  'Console' => 
  array (
    0 => 
    array (
      'bConsole' => 1,
      'ConsoleReference' => 'help',
      'EnableConsole' => true,
      'ViewPermissions' => 1,
    ),
  ),
  'accountData' => 
  array (
    0 => 
    array (
      'AccountName' => 'CSSName',
      'accountBalance' => 
      array (
        0 => 450440561,
        1 => 278575333,
        2 => 325290889,
        3 => 1838037277,
        4 => 155835317,
      ),
    ),
    1 => 
    array (
      'AccountName' => 'CSSCustomer',
      'accountBalance' => 
      array (
        0 => 5230834,
        1 => 3008402,
        2 => 3008400,
        3 => 3231485,
        4 => 9025200,
      ),
    ),
  ),
);

// This is the top array key of the data you want to retrieve.
$data = $arr["accountData"];

for ($i = 0; $i < count($data); $i++){
    
    echo $data[$i]["AccountName"];
    
    // I created another loop to retrieve all the values in the accountBalance
    foreach ($data[$i]["accountBalance"] as $item){
       echo $item;
    }
   
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM