1
Array
(    [Fixed Assets] => Array
    (
        [0] => 150
        [1] => Array
            (
                [Equimpent] => Array
                    (
                        [0] => Office Computer
                        [1] => Office Printer
                    )
            )
        [2] => Array
            (
                [Furniture and Fixtures] => Array
                    (
                        [0] => Desk
                        [1] => Desk Chair
                    )
            )
    )
)

階層的なアカウントの名前付けと番号付けのスキーマとして使用されるアカウント番号は、上記のサンプル配列から次のように導出できます...

  • 固定資産親アカウント)#150
  • Equimpent固定資産の子)#150-1
  • 家具および備品固定資産の子)#150-2
  • デスクチェア家具と備品の子)#150-2-1

私のパズルは、目的の新しいアカウント名と、そのターゲットの親アカウントの派生アカウント番号のみを指定して、配列への新しいアカウントの追加をコーディングする方法です。

例えば...

<?php  
//Chart of Accounts
$coa = array('Fixed Asset'=>array(150,array('Equimpent'=>array('computer','printer')),array('Furniture and Fixtures'=>array('desk','chair'))));
//global $coa;
$new_account ="Office File Cabinet";//from ajax post
$target_base_no ="150-2";//from ajax post
//won't know if or how many subkeys will may be included 
//but would result in something like...

$coa['unknown_parent_of_acct_no_150'][2][] = $new_account;
?>

私は完全にブロックされています...相互に私は尋ねるかもしれません...アカウント番号150-2のアカウント名をどのように決定できますか?これがコンテキスト内のCOAアレイです。

Array
(
[Cash Bank] => Array
    (
        [0] => 100
        [1] => Checking
        [2] => Paypal
        [3] => Petty Cash
        [4] => Savings
        [5] => Deposits Pending
    )

[Accounts Receivable] => Array
    (
        [0] => 110
        [1] => AR-AlternaMart
    )

[Inventory] => Array
    (
        [0] => 120
    )

[Other Current Assets] => Array
    (
        [0] => 130
        [1] => Pre-Paid Hosting
    )

[Fixed Assets] => Array
    (
        [0] => 150
        [1] => Array
            (
                [Equipment] => Array
                    (
                        [0] => Computer
                        [1] => Printer
                    )

            )

        [2] => Array
            (
                [Furniture And Fixtures] => Array
                    (
                        [0] => Desk
                        [1] => Desk Chair
                    )

            )

    )

[Accumulated Depreciation] => Array
    (
        [0] => 160
        [1] => AD-Computer
        [2] => AD-Printer
        [3] => AD-Desk
        [4] => AD-Desk Chair
    )

[Accounts Payable] => Array
    (
        [0] => 200
        [1] => AP-Unearned Shipping
    )

[Credit Cards Payable] => Array
    (
        [0] => 210
        [1] => Wells Fargo Visa
    )

[Sales Tax Payable] => Array
    (
        [0] => 220
        [1] => CO
        [2] => 80227
        [3] => 80214
        [4] => IL
    )

[Accrued Payroll Taxes] => Array
    (
        [0] => 230
    )

[Other Current Liabilities] => Array
    (
        [0] => 240
    )

[Loans Payable] => Array
    (
        [0] => 270
    )

[Notes Payable] => Array
    (
        [0] => 280
    )

[Capital] => Array
    (
        [0] => 300
    )

[Drawing] => Array
    (
        [0] => 320
    )

[Sales] => Array
    (
        [0] => 400
    )

[Other Income] => Array
    (
        [0] => 401
        [1] => Shipping
    )

[Commissions] => Array
    (
        [0] => 402
        [1] => AlternaMart Commissions
    )

[Sales Discounts] => Array
    (
        [0] => 450
    )

[Sales Returns and Allowances] => Array
    (
        [0] => 451
    )

[Shipping Discounts] => Array
    (
        [0] => 452
    )

[Reimbursed Shipping] => Array
    (
        [0] => 453
    )

[Cost of Goods Sold] => Array
    (
        [0] => 500
        [1] => COGS Shipping
    )

[Expense] => Array
    (
        [0] => 600
        [1] => BSC Checking
        [2] => Paypal Transaction Fees
        [3] => Alternamart Transaction Fees
        [4] => Commissions Expense
        [5] => Interest Expense
        [6] => Internet Service
        [7] => Web Hosting
        [8] => Rent Expense
        [9] => Telephone
        [10] => Utilities
        [11] => Postage
        [12] => Office Supplies
        [13] => Miscellaneous Supplies
        [14] => Advertising
        [15] => Salaries And Wages
        [16] => Payroll Taxes
        [17] => Dues And Subscriptions
        [18] => Miscellaneous Expenses
        [19] => Legal And Accounting
        [20] => Insurance
        [21] => Vehicles Expense
        [22] => Depreciation Expense
        [23] => Travel And Entertainment
        [24] => Bad Debt Expense
        [25] => Ask Accountant
    )

[Ask Accountant] => Array
    (
        [0] => 900
    )

)。

4

1 に答える 1

0

私がそれを正しく理解すれば:...

分割$target_base_no-配列で値 = 150 ($arr[0]) を$arr = explode('-', $target_base_no) 検索します。次のようになります。$coa

    foreach($coa as $row) {
       if ($arr[0] == $row[.....]
    }

2 番目に分割された値 ($arr[1]) を使用して、挿入する場所を特定します。

編集済み: 正しい値に直接アクセスするには、逆インデックス配列を作成する必要があります。数値をキーとして保存し、テキスト値を値として保存します($coa配列のインデックスとして使用できます:

$index = array();
foreach($coa as $key => $value) {
     $index[$value[0]] = $key;
}

その後、データにアクセスするだけです$coa[$index[$arr[0]]](フィールドが存在するかどうかを確認する必要があります)

于 2012-05-05T21:37:09.527 に答える