Jump to content

[SOLVED] passing params


zang8027

Recommended Posts

I got a php file called nav.php with the following code:

 

<?php

function navigation($home, $resume, $port, $contact)
{
	echo '

	<ul>
		<li><a href="index/"><img src="images/$home.png" alt="Home Page" /></a></li>
		<li><a href="resume/"><img src="images/$resume.png" alt="Resume" /></a></li>
		<li><a href="portfolio/"><img src="images/$port.png" alt="Portfolio Pieces" /></a></li>
		<li><a href="contact/"><img src="images/$contact.png" alt="Contact" /></a></li>
	</ul>
	';

}

?>

 

 

Then, in my main file, i am using require_once 'nav.php';.

 

Then, i am calling the function navigation("homeBtn", "resumeBtn", "portBtn", "contactBtn);

 

I am getting $contact.png etc.. instead of contactBtn so it acts like its not accepting my params.

 

Any idea?

Link to comment
https://forums.phpfreaks.com/topic/166389-solved-passing-params/
Share on other sites

You need to use double quotes instead of single quotes for it to show the value of the variable. Or you could just do,

' . $home . '

etc.

 

So,

<?php

   function navigation($home, $resume, $port, $contact)
   {
      echo '

      <ul>
         <li><a href="index/"><img src="images/' . $home . '.png" alt="Home Page" /></a></li>
         <li><a href="resume/"><img src="images/' . $resume . '.png" alt="Resume" /></a></li>
         <li><a href="portfolio/"><img src="images/' . $port . '.png" alt="Portfolio Pieces" /></a></li>
         <li><a href="contact/"><img src="images/' . $contact . '.png" alt="Contact" /></a></li>
      </ul>
      ';

   }

?>

is one way.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.