开发者

split out the key and the value?

开发者 https://www.devze.com 2023-03-24 23:12 出处:网络
the array shows as this: $_ADMINLANG[\'global\'][\'jumppage\'] = \"Jump to Page\"; $_ADMINLANG[\'global\'][\'go\'] = \"Go\";

the array shows as this:

$_ADMINLANG['global']['jumppage'] = "Jump to Page";
$_ADMINLANG['global']['go'] = "Go";
$_ADMINLANG['months']['january'] = "January";
$_ADMINLANG['months']['february'] = "February";
.......

now, i want to output the above data as this:

 $_ADMINLANG['global']['jumppage'] =
 $_ADMINLANG['global']['go'] 开发者_运维百科=
 $_ADMINLANG['months']['january'] =
 "Jump to Page";
"Go";
"January";

how do i do ? thank you.


If you want to simply print the values as you mentioned, then this must be the code.

$temp = '';
foreach ($_ADMINLANG as $key1 => $arr) {
    foreach ($arr as $key2 => $val) {
        echo  '$_ADMINLANG["'.$key1.'"]["'.$key2.'"] = <br />';
        $temp .= $val.'<br/>';
    }
}
echo $temp;


just loop through the array and echo the keys (first output) and for the second output echo the values.

have a look at the foreach function: http://php.net/manual/en/control-structures.foreach.php


http://www.php.net/manual/en/function.array-keys.php - returns keys of array

http://www.php.net/manual/en/function.array-values.php - returns values of array


I really don't know if this is just about outputting the array contents, but if it is, here you go:

$_ADMINLANG['global']['jumppage'] = "Jump to Page";
$_ADMINLANG['global']['go'] = "Go";
$_ADMINLANG['months']['january'] = "January";
$_ADMINLANG['months']['february'] = "February";

foreach ($_ADMINLANG as $sub) {
    foreach ($sub as $key => $val) {
        echo $val, '<br />';
    }
}
0

精彩评论

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