Jump to content

[SOLVED] echoing and array help :(


fellixombc

Recommended Posts

Its echoing out a '1' one the homepage..and every other page..not what the variables say.. website: http://webdevshare.com

 

 

here is my script i wrote... please help?

 

  <?php
  
  ###############################
  ##Copyright(C)Webdevshare.com##
  ###############################
  
  
$home = "hello, homepage"; //start of home  content

//end of home content
$tutorials = "tutorials!"; // start of tutorials content

//end of tutorials content
$memberships = "memberships!!! XD"; // Start of memberships content

// end of memberships content
$downloads = "downloads lul"; //Start of downloads content

//end of downloads content
$chat = "chatting ftw?"; // Start of chat box

//End of chat box

$pages = array    (    array($choice => $home, 'url' => '/'),
                      array($choice => $tutorials, 'url' => '/tutorials.php'),
                     array($choice => $memberships, 'url' => '/memberships.php'),
                     array('choice' => '$downloads', 'url' => '/downloads.php'),
                     array('choice' => '$chat', 'url' => '/chat.php')
                );

$currentpage = $_SERVER['REQUEST_URI'];
foreach($pages as $page)
{
$choice = ($page['url'] == $currentpage);
    echo $choice;
} 
?>

Link to comment
Share on other sites

I think you need to spend more time on the basics of php.

 

Play around a bit using this code:

 

print "<pre>"; var_dump($pages); print "</pre>";

 

That will show you the contents of any variable ($pages in this case).  You should do the same for $currentpage, so you can see what you are comparing against.

 

This line:

 

$choice = ($page['url'] == $currentpage);

 

says "Compare $page['url'] and $currentpage.  If they are equal, set $choice to true.  Otherwise set it to false"

 

When you try to print out "true", that's when you see 1.  Instead you should be printing something from $page, eg "echo $page['choice']" or "echo $page['url']"

Link to comment
Share on other sites

I think you need to spend more time on the basics of php.

 

Play around a bit using this code:

 

print "<pre>"; var_dump($pages); print "</pre>";

 

That will show you the contents of any variable ($pages in this case).  You should do the same for $currentpage, so you can see what you are comparing against.

 

This line:

 

$choice = ($page['url'] == $currentpage);

 

says "Compare $page['url'] and $currentpage.  If they are equal, set $choice to true.  Otherwise set it to false"

 

When you try to print out "true", that's when you see 1.  Instead you should be printing something from $page, eg "echo $page['choice']" or "echo $page['url']"

Ill give that a try, and sorry, I've just started learning php..and kinda went head in =/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.