3

Hello I'm learning php but I'm hard stuck on what the next step should be. I have a multidimensional array:

$fruits=array(
    array(
        "name"=>"The Banana", 
        "color"=> "Yellow", 
        "information"=>"bananas have lots of fiber."),
    array(
        "name"=>"The Strawberry", 
        "color"=> "Red", 
        "information"=>"strawberries have lots of vitamin."),
;

I'm able to show the array with my for each function

function show_fruits($fruits){    
    foreach($fruits as $fruit) 
        echo $fruit[name]."<br>".$fruit[color];
}

But now I want to pass the information into a new single page where it also shows the "information" key depending on the selection.

I was trying to use $_GET and embed the URL into my function but I was only getting "the" in the url result.

If anyone have better idea or how to proceed I would greatly appreciated!

cegfault
  • 6,442
  • 3
  • 27
  • 49
JJB
  • 31
  • 1
  • 1
    For a complex data structure like this, I suggest using session. –  Feb 26 '19 at 00:33
  • You could use json_encode to create a json string and pass it. But best would probably be to use $_SESSION. Make sure you delete the $_SESSION after. – Maciek Semik Feb 26 '19 at 01:00

2 Answers2

0

You can store it in the $_SESSION global variable

Bryan Estrito
  • 673
  • 2
  • 6
  • 17
0

you can use $_SESSION if you want to pass the array from a page to an other, and include if you want to pass the function

Zack Heisenberg
  • 499
  • 6
  • 12