Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

php - How do I print this multidimensional array?

Lets say I have the following array:

Array ( [1284487200] => Array ( [title] => first title [link] => http%3A%2F%2Fexample1.com ) [1261271380] => Array ( [title] => second title [link] => http%3A%2F%2Fexample2.com )

I want to print the array like this:

<a href="http://example1.com">first title - 1284487200</a><br>
<a href="http://example2.com">second title - 1261271380</a><br>

Any ideas would be greatly appreciated!

UPDATE: the 2 answers provided have the same error in that my domain is included in the link, eg. http://www.mydomain.com/http%3A%2F%example1.com

Any way I can correct that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
foreach ($array as $key => $entry) {
    echo "<a href="{$entry['link']}">{$entry['title']} - {$key}</a><br>";
}

See: http://php.net/manual/en/control-structures.foreach.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...