开发者

Multi-dimensional array in php

I would like to create a multi-dimensional array with two variables but don't know how.

This is what i have so far;

 $_SESSION['name'][] = $row_subject['name'];
 $_SESSION['history'][]= $_SERVER['REQUEST_URI'];

I wanted to know if this is possible?

$_SESSION['name'开发者_C百科][] = $row_subject['name'],$_SERVER['REQUEST_URI'];

i want to get the name of a programme which is generated via a data base and also to retrieve the url. What i am actually doing once the name is retrieve, i want to make that a link which the url would be necessary.

any help would be appreciated.

Thanks


I'm not sure what you want to do but the correct notation for your second example could be

$_SESSION['name'][] = array("name" => $row_subject['name'], 
                            "history" => $_SERVER['REQUEST_URI']);

This pushes an associative array with the keys "name" and "history" to the array $_SESSION["name"].

You could then access the entries like so:

echo $_SESSION["name"][0]["name"];
echo $_SESSION["name"][0]["history"];

if you repeat the command with different data:

$_SESSION['name'][] = array("name" => $row_subject['name'], 
                            "history" => $_SERVER['REQUEST_URI']);

the next entry would be addressed like so:

You could then access the entries like so:

echo $_SESSION["name"][1]["name"];
echo $_SESSION["name"][1]["history"];

and so on.


$_SESSION['name'][] = array($row_subject['name'], $_SERVER['REQUEST_URI']);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜