Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts

    Assigning a variable to an echoed string

    I have a function called whatToDo(). In the function, it echoes a string like "Hit" or "Split" (it's a Blackjack program). I need to set a variable to whatever whatToDo() echoes, but all my current code does is echo, not set the variable to what's being echoed. How do I set the variable without anything being echoed? In the code below, setting $haystack just echoes whatToDo(), it doesn't get set to "hit";

    code:
    Code:
    function haystack($whichDeck)
    {
    	// for simplicity's sake, we will just pretend this function echoes "Hit" every time
    	echo "Hit";
    }
    
    $haystack = strtolower(whatToDo($_GET["whichDeck"]));
    if(substr_count($haystack,"hit") > 0) // the player should hit
    {
    	setGrade($_SESSION["grade"]+1);
    	setPossibleGrade($_SESSION["possibleGrade"]+1);
    }
    else
    	setPossibleGrade($_SESSION["possibleGrade"]+1);
    Last edited by wldrumstcs; 02-24-2010 at 04:15 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    function haystack($whichDeck)
    {
    	return 'Hit';
    }

  • Users who have thanked MattF for this post:

    wldrumstcs (02-24-2010)

  • #3
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts
    Sweet mother of god I'm an idiot. I guess that's what 3 hours of sleep will do to you. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •