2015-01-05 4 views
-2

PHP가 처음이므로 PHP 파일을 실행할 때 다음과 같은 PHP 오류가 발생합니다. 는 약간의 도움이 많이 주시면 감사하겠습니다, 감사 매우 사전에 여기 파일을 실행할 때 PHP 구문 오류가 발생했습니다.

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\facebook\arrays.php on line 21

내 코드입니다 :

<html> 
     <head> 
      <title> An empty html page </title> 
     </head> 
     <body> 
      <!-- this is an html comment --> 
      <!-- currently the body is empty --> 
      <?php 

      echo "<p>hello world</p>"; 

      $name = "Peter Pan"; 
      $address = "Neverland"; 
      $age = "14.75"; 

      $unnamed_lost_boys = array(4.5, 6, 7, 5.5, 5.25, 4, 7, 6.75); 
      $named_lost_boys = array("Tootles"=> 4.5, 
            "Nibs"=>6, 
            "Slightly"=>7.5); 

      echo "The age of Nibs is $named_lost_boys['Nibs']"; 

      function print_details ($name, $age, $address) 
      { 
      echo "My name is $name, I'm from $address and I'm $age years old"; 
      echo "<br>"; 
      echo 'My name is '.$name.",I'm from ".$address." and I'm $age years old"; 
      echo "<br>"; 
      } 
      print_details($name, $age, $address); 

      ?> 
     </body> 
    </html> 

답변

2

당신은 중괄호에 그들을 배치하지 않고 문자열 보간의 배열을 사용할 수 없습니다; 그래서 사용

echo "The age of Nibs is {$named_lost_boys['Nibs']}"; 

을 또한 the documentation

+0

최고 .... 감사합니다 – Hollywood

2

시도 참조 :

echo "The age of Nibs is " . $named_lost_boys['Nibs']; 
관련 문제