PHP如何解决selectbox中的嵌套数组值

时间:2017-01-04 06:48:56

标签: php mysql arrays json nested

我希望在选择运算符时显示它,它应该列出operator_id 45/46等下的所有状态。

它不使用任何数据库。

但不是"插入数组"我想插入我的函数,最后创建一个数组。如果我插入数组,它会说:

[0] => Array
        (
            [operator_id] => 45
            [company_id] => 1
            [company_name] => Aircel
            [operator_name] => Aircel
            [mode_name] => Normal
            [id_name] => Mobile/Phone Number
            [pattern] => ^([1-9][0-9]{9})$
            [min] => 1
            [max] => 9999
            [def] => 10 digit number
            [payment_type] => Prepaid
            [states] => Array
                (
                    [0] => Array
                        (
                            [state_id] => 9
                            [state_code] => 4
                            [state_name] => karnataka
                        )
                      [1] => Array
                        (
                            [state_id] => 10
                            [state_code] => 5
                            [state_name] => andra pradesh
                        )

                )

            [cities] => Array
                (
                )

        )
[1] => Array
        (
            [operator_id] => 46
            [company_id] => 1
            [company_name] => *****
            [operator_name] => *****
            [mode_name] => Normal
            [id_name] => Mobile/Phone Number
            [pattern] => ^([1-9][0-9]{9})$
            [min] => 1
            [max] => 9999
            [def] => 10 digit number
            [payment_type] => Prepaid
            [states] => Array
                (
                    [0] => Array
                        (
                            [state_id] => 3
                            [state_code] => 11
                            [state_name] => tamilnadu
                        )

                )

            [cities] => Array
                (
                )

        )

但不是"插入数组"我想插入我的函数,它创建了一个

我试过

<select name="countrycode" class="form-control" required>
<option value="">Select Operator</option>
<?php                        
foreach ($arryOperators as $arryOperator) {
echo '<option value="'.$arryOperator['operator_id'].'">'.$arryOperator['operator_name'].'</option>';    
$states .= echo '<option value="'.$arryOperator['state_id'].'">'.$arryOperator['state_name'].'</option>';   

}
?>                            
</select> 

0 个答案:

没有答案