Home > Backend Development > PHP Tutorial > 读取数组的问题

读取数组的问题

WBOY
Release: 2016-06-23 13:37:40
Original
924 people have browsed it

我想设置一个函数用来读取基本配置资料(数组),但是不知道怎么设置才能应对各种数组
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;}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template