-1

I have a less advanced question for you programmers out there, that i need help with.

Simply i am trying to add 2 elements of my array into a echo display statement.

This is not so hard but what im having issues with is being able to concatenate the parenthesis with the array to show as : The Matrix (1999).

i don't want the the parenthesis to be included in the array just to add the elements within them.

any help would be greatly appreciated, thanks guys (MY GUESS IS THAT I'M NOT PROPERLY CONCATENATING THE ELEMENTS.)

CODE IM USING::

<?php $movie = array(
"title" => "The Matrix"
"year" => "1999"
 ); ?>

<h1><?php 
echo $movie["title"] ."(" . $movie["year"] .")"
;?></h1>

OKAY SO I REALIZED I MISSED THE COMMA. BUT THAT WAS NOT MY PROBLEM. THAT WAS A TYPO ON MY PART ON HERE.

THIS WAS AN EXERCISE THAT I NEEDED TO PASS .

TASK : Right now, the element has the year of the first movie as a static piece of text . Replace that with a PHP command to display the year of the second movie from the array.(Be sure to leave the parentheses intact.)

what i have is i created the array $movie = array();

then i created the elements within the array

<?php $movie =array(
"title"=>"Empire Strikes Back", 
"year" => "1980"; )?>

so what i need to do is echo out the elements which i pass the first stage which is just adding the title variable:

<?php echo $movie["title"];?> (1985)

step two is adding the year element in the array, i have tried everything from concatenation of the parenthesis and adding the year to creating two separate php blocks . my problem is that i keep getting the error that my exercise 3 doesn't seem to pass.

<?php echo $movie["title"] . "(" .$movie["year"] . ")" ;?>
<?php echo $movie["title"];?> (<?php echo $movie["year"]; ?>)

ANY SUGGESTIONS WOULD BE GREAT. I SEEM TO BE STUCK ON THIS FOR COUPLE DAYS NOW. I KNOW THIS HAS POTENTIAL TO BE CONFUSING IF YOU DONT SEE THE EXERCISE, BUT THIS WAS THE BEST I COULD DO FOR A 8 PART EXERCISE.

thanks

4

2 回答 2

6

Your missing a comma after Matrix",<<<

<?php $movie = array(
"title" => "The Matrix",
"year" => "1999"
 ); ?>
于 2013-01-18T21:31:50.397 回答
0

你必须知道 数组是语言结构。它接受任意数量的逗号分隔key => value对作为参数。所以,你错过了逗号。对于最后一个数组元素,逗号可以省略。

于 2013-01-18T21:38:15.913 回答