简体   繁体   English

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

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

i am stucked trying to get information from an array file in php.我被困在试图从 php 中的数组文件中获取信息。 I was able to read it and convert to php array, but now i want to print the stored information in a table but always i get incorrect values.我能够读取它并转换为 php 数组,但现在我想在表格中打印存储的信息,但总是得到不正确的值。

¿how can i retrieve the information correctly? ¿我怎样才能正确检索信息?

Array:大批:

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 is the array which i want to show as datatable or table. accountData 是我想显示为数据表或表的数组。 I'll glad for your help我会很高兴你的帮助

used print_r($content) to show this:使用 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
                        )

                )

        )

)

I used the array you gave and created a solution below.我使用了您提供的数组并在下面创建了一个解决方案。 This solution is not the only way to do this.此解决方案不是执行此操作的唯一方法。 But it is easy to understand.但这很容易理解。

You can read further on the subject and look at other examples of using associative arrays from the official docs.您可以进一步阅读该主题并查看官方文档中使用关联 arrays 的其他示例。

Here's the sandbox code sample link for the solution.这是解决方案的沙盒代码示例链接。

http://sandbox.onlinephpfunctions.com/code/532935a21f5f80d8e6d128bed69be18096093ab2 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