Jump to content
MakeWebGames

Need some help.


Haunted Dawg
 Share

Recommended Posts

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

Link to comment
Share on other sites

Guest Anonymous

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";

?>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...