Support » Fixing WordPress » Extremely simple function not working, help?

  • Resolved phpchick


    function getstockstats($stocksymbol)
     if ( $stocksymbol == "aapl" ) {
    	$result = "Your name is someguy!<br />";
    return $result;

    Anyone have any suggestions? super simple

Viewing 9 replies - 1 through 9 (of 9 total)
  • What are you trying to do?

    Shouldn’t you add:

    $baboon = getstockstats(‘aapl’);

    echo $baboon;


    Moderator Andrew Nevins


    What isn’t working, in which line?
    What, if any, are the errors shown?

    whats the difference between echo and return ?

    All I wanted to do was print “yourname is some guy”

    I changed to this,

    function getstockstats($stocksymbol)
     if ( $stocksymbol == "aapl" ) {
    	$result = "Test!<br />";
    echo $result;

    and it worked. But shouldnt returning $result also print it out?



    Forum Moderator

    however simple functions you are trying to code, you need to learn the basics.

    One last question,

    function widget($args, $instance)
      function getstockstats($stocksymbol)
    	$objYahooStock = new YahooStock;
    	foreach( $objYahooStock->getQuotes() as $code => $stock)
        Code: <?php echo $stock[0]; ?> <br />
        Name: <?php echo $stock[1]; ?> <br />
        Last Trade Price: <?php echo $stock[2]; ?> <br />
        Last Trade Date: <?php echo $stock[3]; ?> <br />
        Last Trade Time: <?php echo $stock[4]; ?> <br />
        Change and Percent Change: <?php echo $stock[5]; ?> <br />
        Volume: <?php echo $stock[6]; ?> <br /><br />
     if ( $stocksymbol == "aapl" ) {
    	$result = "Test!<br />";
    	echo $result;
        echo $after_widget;

    Why doesn’t my function work when I add the echos inside that foreach loop? I have a feeling it is some sort of permissions issue but am not sure


    The directory starts in the plugin root and NOT the directory that the file is located in.

    I changed

    and now it works. ARGH

    One more issue


    That line is getting read as $stocksymbol
    What do I have to do change in order to make it read the variable, as opposed to $stocksymbol?

    I’ve tried wrapping in braces like


    but it did not work


    I removed the quotes.


    Thank you everybody for so much help 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Extremely simple function not working, help?’ is closed to new replies.