![](/img/trans.png)
[英]AngularJS Get all values from an array in Javascript and push it to another array
[英]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.