0

I need to be able to get the data out of the following functions:
getStuff();
getRelateStuff();
getRelatedStuffInStuff();

Begin Code:

function getStuff()
{
   return array("It", "Works");
}

function Stuff()
{
   $value = array(getStuff());
   foreach ($value as $key => $value) 
   {
      echo "$key  $value <br />\n";
   }

}

function getRelatedStuff()
{
   return array("hello" => "world", "cake"=> "is a lie");
}

function RelatedStuff()
{

   $value = array(getRelatedStuff());
   foreach ($value as $key => $value) 
   {
      echo "$key  $value <br />\n";
   }

}

//Related in Stuff
function getRelatedStuffInStuff()
{
   $s1 = array("hello" => "world", "cake"=> "is a lie");
   $s2 = array("apple" => "mac", "microsoft"=> "windows", "linus" => "linux");
   $s3 = array("OSX" => "10.6", "Ubuntu" => "11.04", "Windows" => "7");
   return array($s1, $s2, $s3);
}

function RelatedInStuff()
{

   $value = array(getRelatedStuffInStuff());
   foreach ($value as $key => $value) 
   {
      echo "$key  $value <br />\n";
   }

}

?>

When I try to view this page in a web browser it just shows a blank page. I am doing anything correctly? What should or what can I change?

2
  • the piece of code you posted (I think it's the second time I see it) just has functions definitions. You need to call those functions (and actually generate HTML somewhere if you want it to be pretty). Commented Jun 26, 2011 at 11:18
  • where is your getStuff() method? and where are your function calls? Commented Jun 26, 2011 at 11:18

2 Answers 2

4

If this is your full code... you have to call the functions.

Also your functions already return an array so you don't need to wrap those calls in array(...).

Sign up to request clarification or add additional context in comments.

Comments

2

Try to add this at the end of your code (the ?> is the last line in what you posted):

?>
<html><body>
<?php
RelatedInStuff();
?>    
</body></html>

This will actually generate some HTML and call one of your functions.

6 Comments

well there you go, you've started to see some output. Now you need to rework your code. Start with trying to display, just one array with one function call. Once you've got that working as you want, add the other functions in one at a time.
@Mat I can't seem to figure out what I am doing wrong. Thoughts? I added the HTML and as previously stated I get the "O Array" output.
You need to learn more about PHP arrays. Try with much simpler things than what you posted.
@Mat for some reason I have always struggled with Array. I don't exactly know why, just have though.
you're trying to do too much at a time. Practice with a single array and try to print only that contents. You don't actually need a function for this. Once you have that working, try with two, make a function. Don't add anything more until you've actually understood what you did in the previous step.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.