我在php中有这个多维数组,当用户在www.web.com/index?page=graphicdesigner
时我需要我从<{> 1}}的获取读取参数页面。我需要经历这个数组并在当前位置返回数组。
所以,如果我在上面的网址,我会得到返回$_GET["page"
=&gt;的图形设计师
echo $array["urlanchor"];
怎么可能?我可以得到正确的PHP代码,它将运行良好。
答案 0 :(得分:0)
使用查询参数作为键从多维数组中选择数组:
$jobs = array(
"graphicdesigner" => array(
"urlanchor" => "graphic-designer",
"og:title" => "graphicdesigner ogtitle",
"og:description" => "graphicdesigner ogdescription",
"og:image" => "",
"og:url" => ""
),
"uidesigner" => array(
"urlanchor" => "ui-designer",
"og:title" => "uidesigner ogtitle",
"og:description" => "uidesigner ogdescription",
"og:image" => "",
"og:url" => ""
)
);
$page = $_GET["page"];
$pageArr = $jobs[$page];
echo $pageArr['urlanchor'];
答案 1 :(得分:0)
如果你有$jobs
。
$jobs = array(
"graphicdesigner" => array(
"urlanchor" => "graphic-designer",
"og:title" => "graphicdesigner ogtitle",
"og:description" => "graphicdesigner ogdescription",
"og:image" => "",
"og:url" => ""
),
"uidesigner" => array(
"urlanchor" => "ui-designer",
"og:title" => "uidesigner ogtitle",
"og:description" => "uidesigner ogdescription",
"og:image" => "",
"og:url" => ""
)
);
您应该使用echo $job['graphicdesigner']['urlanchor'] ;
来获取输出。