PHP数组有助于从密钥中获取值

时间:2022-04-28 20:49:35

I have a variable that looks likes this,

我有一个看起来像这样的变量,

$rslt['expected_salary_level']

This returns a string similar to LEVEL_3, in another array that looks like this I have a set of salaries,

这将返回一个类似于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] => 
        )

)

How do I get at the associated nice name?

我怎么得到相关的好名字?

2 个解决方案

#1


8  

If I understand you correctly, $rslt['expected_salary_level'] returns the key for this array in your example. Assuming that this array is called $array, I think this is what you want:

如果我理解正确,$ rslt ['expected_salary_level']会返回示例中此数组​​的键。假设这个数组被称为$ array,我认为这就是你想要的:

$array[$rslt['expected_salary_level']]['nice_name']

#2


0  

I think this is a simple way to get array to array key values :

我认为这是将数组转换为数组键值的简单方法:

$own_array_result = $rslt['expected_salary_level']['LEVEL_3']['nice_name'];

echo $own_array_result;

OUTPUT => £15,000 - £20,000

输出=> 15,000英镑 - 20,000英镑

#1


8  

If I understand you correctly, $rslt['expected_salary_level'] returns the key for this array in your example. Assuming that this array is called $array, I think this is what you want:

如果我理解正确,$ rslt ['expected_salary_level']会返回示例中此数组​​的键。假设这个数组被称为$ array,我认为这就是你想要的:

$array[$rslt['expected_salary_level']]['nice_name']

#2


0  

I think this is a simple way to get array to array key values :

我认为这是将数组转换为数组键值的简单方法:

$own_array_result = $rslt['expected_salary_level']['LEVEL_3']['nice_name'];

echo $own_array_result;

OUTPUT => £15,000 - £20,000

输出=> 15,000英镑 - 20,000英镑