Print an array value when its key matches with a variable (PHP) -


i have "album.php" page 4 albums; when click on 1 of them links "gallery.php" showing photos of specific album. put specific title in "gallery.php" depending on album clicked user , in nice , clean way. gallery.php:

$query_url = $_server['query_string']; $pageid = substr($query_url, 6); $album_title = array("album1" => "title1",                      "album2" => "title2",                      "album3" => "title3"); while($album_title[key] = $pageid)   {    echo '<div id="album_title">            <h2 class="body_text">'.$album_title[value].'</h2>          </div>';   } 

i thought instead of less dynamic:

if($pageid = "album1")   {echo "title1";} if($pageid = "album2")   {echo "title2";} etc. 

my problem don't know how "say":

when(array[key] = $pageid)   {    echo 'the correspondent array[value]';   } 

thanks everyone!

[edit] voting negatively without explication doesn't solve problem in world, mate. 'cause used "while" instead of "foreach" in example? know existence tried multiple times without success.

provinding $pageid "album1" wouldn't need loop:

echo '<div id="album_title">   <h2 class="body_text">' . $album_title[$pageid] . '</h2> </div>'; 

check out.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -