[英]PHP array help getting a value from the key
我有一個看起來像這樣的變量,
$rslt['expected_salary_level']
這會在另一個數組中返回類似於LEVEL_3的字符串,如下所示,我有一組薪水,
Array
(
[LEVEL_1] => Array
(
[nice_name] => under £10,000
[low] => 1
[high] => 10000
)
[LEVEL_2] => Array
(
[nice_name] => £10,000 - £15,000
[low] => 10000
[high] => 15000
)
[LEVEL_3] => Array
(
[nice_name] => £15,000 - £20,000
[low] => 15000
[high] => 20000
)
[LEVEL_4] => Array
(
[nice_name] => £20,000 - £25,000
[low] => 20000
[high] => 25000
)
[LEVEL_5] => Array
(
[nice_name] => £25,000 - £30,000
[low] => 25000
[high] => 30000
)
[LEVEL_6] => Array
(
[nice_name] => £30,000 - £40,000
[low] => 30000
[high] => 40000
)
[LEVEL_7] => Array
(
[nice_name] => £40,000 - £50,000
[low] => 40000
[high] => 50000
)
[LEVEL_8] => Array
(
[nice_name] => £50,000 - £100,000
[low] => 50000
[high] => 100000
)
[LEVEL_9] => Array
(
[nice_name] => £100,000 or more
[low] => 100000
[high] => 9999999
)
[LEVEL_VOLUNTARY] => Array
(
[nice_name] => Voluntary
[low] =>
[high] =>
)
[LEVEL_UNSPECIFIED] => Array
(
[nice_name] => Not specified
[low] =>
[high] =>
)
)
如何獲得關聯的好聽的名字?
如果我對您的理解正確, $rslt['expected_salary_level']
將在您的示例中返回此數組的鍵。 假設此數組稱為$array
,我想這就是你想要的:
$array[$rslt['expected_salary_level']]['nice_name']
我認為這是獲取數組鍵值的簡單方法:
$own_array_result = $rslt['expected_salary_level']['LEVEL_3']['nice_name'];
echo $own_array_result;
輸出=> £15,000-£20,000
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.