欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

读取数组的问题

程序员文章站 2022-06-07 20:47:29
...
我想设置一个函数用来读取基本配置资料(数组),但是不知道怎么设置才能应对各种数组
function get_base_data($name,$value){
$web_data_init=array(
"currencies"=>array("GBP","USD","JPY","EUR","CAD","CNY"),

"country_D"=>array
(
"UK"=>"GBP",
"DE"=>"EUR",
"IT"=>"EUR",
"FR"=>"EUR",
"US"=>"USD",
"UK"=>"GBP",
"JP"=>"JPY",
"CA"=>"CAD",
"CN"=>"CNY",
),
"orderstatus"=>array(
"1"=>array("label label-warning","未发货"),
"2" =>array("label label-primary","已发货"),
"0" =>array("label label-default","已取消"),
"3" =>array("label label-success","已完成"),
"4" =>array("label label-danger","退款"),
"5" =>array("label label-info","地址确认中"),
"6" =>array("label label-info","少货"),
);

);
}

请问我这个函数要怎么设置,才能应对各种数组,主要是读取数组值


回复讨论(解决方案)

你的传入参数 $name、$value 含义是什么?打算让函数返回什么?

orderstatus[1][0]=label;orderstatus[1][1]=label-warning;orderstatus[1][2]=未发货;
orderstatus[2][0]=label;orderstatus[1][1]=label-primary;orderstatus[1][2]=已发货;
...............................
应该是这样获取对应的数组中的值

????

function get_base_data($name,$value){    $web_data_init=array(        "currencies"=>array("GBP","USD","JPY","EUR","CAD","CNY"),        "country_D"=>array(                        "UK"=>"GBP",                        "DE"=>"EUR",                        "IT"=>"EUR",                        "FR"=>"EUR",                        "US"=>"USD",                        "UK"=>"GBP",                        "JP"=>"JPY",                        "CA"=>"CAD",                        "CN"=>"CNY",                        ),        "orderstatus"=>array(               "1"  =>array("label label-warning","未发货"),            "2"  =>array("label label-primary","已发货"),            "0"  =>array("label label-default","已取消"),            "3"  =>array("label label-success","已完成"),            "4"  =>array("label label-danger","退款"),            "5"  =>array("label label-info","地址确认中"),            "6"  =>array("label label-info","少货"),         )    );    if(isset($web_data_init[$name][$value])){        return $web_data_init[$name][$value];    }else{        return '';    }}$data = get_base_data("orderstatus","1");if(is_array($data)){    print_r($data);}else{    echo $data;}
相关标签: 读取数组的问题