如何将条件设置为数组值以显示我的自定义字符串

How set conditional to array value to show my custom string

我有复选框字段,我想设置条件,如果 $array[und][1][value] 等于特殊字符打印一些东西...

像这样:

switch ($array) {
    case "1": print 'Starts'; break;
    case "3": print 'Roads'; break;
    case "7": print 'Flys'; break;
    case "9": print 'Awesome'; break;
}

复选框数组:

Array
(
[und] => Array
    (
        [1] => Array
            (
                [value] => 1
            )

        [9] => Array
            (
                [value] => 3
            )

        [42] => Array
            (
                [value] => 7
            )

        [61] => Array
            (
                [value] => 9
            )
    )

)

你必须绕过 $array['und']$array[LANGUAGE_NONE] :

foreach ($array['und'] as $item) {
    switch ($item['value']) {
       // ...
    }
}

您还可以获得以下值:

$values = array_column($array['und'],'value')) ; // [1,3,7,9]