Haunted Dawg Posted September 5, 2008 Share Posted September 5, 2008 All of us need some help in some time. But this is not for people who will say check over your code. Im sure i am pretty into it but ive got a slight problem. So its got to do with array's and etc. <?php $array = array(1 => "Exploring", 2 => "Home", 3 => "Items", 4 => "Checking Mail", 5 => "Checking Events", 6 => "Training", 7 => "Training Donator", 8 => "Criminal Grounds", 9 => "Doing Crime", 10 => "Searching Streets", 11 => "Checking Announcements", 12 => "At Your Job", 13 => "At School", 14 => "At The Hospital", 15 => "At The Jail", 16 => "At The Forums", 17 => "Reading Newspaper", 18 => "TESTING"); $loop = array("explore.php","index.php","inventory.php","mailbox.php", "events.php","gym.php","gym2.php","criminal.php","docrime.php", "streets.php","announcements.php","job.php","education.php", "hospital.php","jail.php","forums.php","newspaper.php","/test.php"); $count = count($loop); $n = -1; $page_e = $_SERVER['PHP_SELF']; if(in_array($page_e, $loop)) { while($n > $count) { $n++; $page = $loop[$array[$n]]; } } ?> Thanks Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 5, 2008 Author Share Posted September 5, 2008 Re: Need some help. Oh yeah, forgot to mention what i want this script to do. What i want it to do is that if you are on that certain page it will display the proper one. For example. If i am on explore.php it should say Exploring as here it is provied: "explore.php" => "Exploring", Thanks Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted September 5, 2008 Share Posted September 5, 2008 Re: Need some help. Associative arrays are one possible solution: <?php $table = array ( 'explore' => "Exploring", 'index' => "Home", 'inventory' => "Items", // etc ); $key = $_SERVER['PHP_SELF']; $key = basename($key); $key = substr($key, 0, strpos($key, ".")); // or combine these... $key = substr($key = basename($_SERVER['PHP_SELF']), 0, strpos($key, ".")); // now lookup the table... if (isset($table[$key])) $page = $table[$key]; else $page = "Game Name"; // and display echo $page; // or in 2 lines: $key = substr($key = basename($_SERVER['PHP_SELF']), 0, strpos($key, ".")); $page = isset($table[$key]) ? $table[$key] : "Game Name"; ?> Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 5, 2008 Author Share Posted September 5, 2008 Re: Need some help. Im not that familiar with php function's, so i just use what i know to try and make it work. Thanks. Quote Link to comment Share on other sites More sharing options...
Floydian Posted September 5, 2008 Share Posted September 5, 2008 Re: Need some help. while($n > $count) Correct me if I'm wrong, but wouldn't $n be less than $count until it's been incremented? ;) Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted September 5, 2008 Author Share Posted September 5, 2008 Re: Need some help. Then again the while was just to random up the count. But i got it fixed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.