简体   繁体   English

如何去思考多维数组?

[英]How to go thought multidimensional array?

I have this multidimensional array in php and I need when user is on www.web.com/index?page=graphicdesigner I read parameter page from get by $_GET["page" ]. 我在php中有此多维数组,当用户在www.web.com/index?page=graphicdesigner上时,我需要从$_GET["page" ]的get中读取参数 I need go throught this array and return array under the current position. 我需要遍历此数组并在当前位置返回数组。

So If I am on url above I will get return echo $array["urlanchor"]; 因此,如果我在上面的url上,我将得到return echo $array["urlanchor"]; => graphic-designer => 图形设计师

 $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" => ""
    )
);

How it is possible? 怎么可能? I can get the correct php code which will be working well. 我可以获得正确的php代码,它将运行良好。

Use the query param as the key to select the array from the multidimensional array: 使用查询参数作为键从多维数组中选择数组:

 $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'];

if you have got $jobs . 如果您有$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" => ""
    )
);

you should use echo $job['graphicdesigner']['urlanchor'] ; 您应该使用echo $job['graphicdesigner']['urlanchor'] ; to get the output. 获得输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM