【发布时间】:2018-08-27 16:29:07
【问题描述】:
我想使用PHP 从多维数组中获取一个值。我将密钥传递给函数,如果密钥包含值(即没有任何数组值),它将返回该值。但是如果该键包含一个数组值,它将返回整个子数组。
我正在为此添加一个示例数组。
<?php
// prepare a list of array for category, subcategory etc...
$category = array(
'Account' => array(
'Show Balance' => array(
'Recharge' => 2300,
'Success' => 12000,
'Failure' => 25000,
),
'Balance History' => 'your balance is very low for last 2 years',
'Mini Statement' => 'This is your mini statement. You can have a look of your transaction details',
'Last Transaction' => 25000
),
'Deposit' => array(
'Deposit Limit' => 40000,
'Make Deposit' => 'Please go to the nearest branch ans deposit the money.',
'Last Deposit' => 12000
),
'FAQ' => array(
'How To Open An Account' => 'Go to your nearest branch fill up a form, submit it to the branch manger with required supporting documents.',
'How To Withdraw Money' => 'Go to any ATM center swipe the card enter pin and get your money.',
'How To Add Money' => 'You need to go to your nearest branch and deposit money over there.'
),
'Loan' => array(
'Home Loan' => 'This is home loan related answer',
'Personal Loan' => 'This is personal loan related answer',
'Car Loan' => 'This is car loan related answer',
'Bike Loan' => 'This is bike loan related answer'
) ,
'Test',
);
现在,如果我将数组 $category 和 'Recharge' 作为参数传递给任何 PHP 函数,它应该返回 2300 作为结果。
现在,如果我将数组 $category 和“显示余额”作为参数传递给任何 PHPfunction,它应该返回我
array(
'Recharge' => 2300,
'Success' => 12000,
'Failure' => 25000,
)
结果。
在谷歌上搜索了很多,但没有得到答案。
【问题讨论】:
-
中的"任何函数"是什么意思"如果我将数组$category和'Recharge'作为参数传递给任何php函数"我>?这没有任何意义。
-
添加那个PHP函数代码
标签: php multidimensional-array extract sub-array array-key