0

So...I am trying to create a multidimensional array for my assignment. Of course, I don't want anyone to give me the answer but I do want to know what exactly is going on. I'm new to PHP so if you have ANY good criticism I'll take it! I'm using MAMP btw. I also did put all of this code into html tags, I just didn't include them here. I'm showing the PHP only. I've tested this multidimensional array in my localhost(this code is not for my assignment)

 <?php $data = array("Pea"=>array(1, 2, 3),"Red"=>"Judy","Jane");echo $data['Red'];?>

This works alright I guess, It only outputs Judy. But the moment I do this

<?php $data = array("Pea"=>array(1, 2, 3),"Red"=>array("Judy","Jane");echo $data['Red'];?>

I get "This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500"

I also tested this other code from a website(also not the code for my assignment)

<?php $families = array("Griffin"=>array("Peter", "Lois", "Megan" ),"Quagmire"=>array("Glenn"),"Brown"=>array("Cleveland", "Loretta", "Junior");echo $families['Griffin'][2];?>    

Guess what? I got the exact same message as before, "This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500"

It's really weird and confusing. This is the code for my assignment.

enter code here
<?php $movies = array ("Thriller"=> array("Jurassic Park", "The Forgotten", "Jurassic World", "John Q", "Mommy's Little Murderer"
),
"Comedy" => array("White Chicks", "Diary of a Wimpy Kid", "While You Were Sleeping", "The Wedding Planner", "Meet Dave"),
"Romance" => array("Sabrina", "Roman Holiday", "Ever After", "Just Wright", "The Princess Diaries"),
"Superhero" => array("Megamind", "The Incredibles", "Spider man:into the Spider verse", "Fantastic Four", "Big Hero 6"),
"Drama" => array("Safety", "The Color Purple", "Akeelah and the Bee", "Imitation of Life", "Hidden Figures");echo $movies[1][0];?>

I don't even think my local host would like this either. Is there something wrong with my PHP or is there something wrong with the localhost?

Nai
  • 1
  • 1
  • 2
    You have a typo at `array("Pea"=>array(1, 2, 3),"Red"=>array("Judy","Jane");` .. missing end `)`. – IncredibleHat Apr 08 '22 at 20:19
  • 1
    @DiegoDeVita That doesn't cause an error. When you try to echo an array, you get the word `Array`. – Barmar Apr 08 '22 at 20:20
  • good point .. I was triggered when I read that and made a wrong assumption. I hope I didn't confuse anyone with that wrong statement before. I apologize. – Diego D Apr 08 '22 at 20:21
  • Using a good IDE will help you avoid mistakes like this. Also, don't cram everything onto one line. – Barmar Apr 08 '22 at 20:21
  • @IncredibleHat Oh, sorry about the way it looks on here. The ); is the end isn't it? I put the ); at the end. – Nai Apr 08 '22 at 20:33

0 Answers0