2014-10-28 2 views
1

$ i18ncoches = "coches"; $ i18nmotos = "motos";새로운 변수에 하나의 문자열과 변수를 결합하는 방법

안녕하세요 문자열과 변수

$apartados=array('coches', 'motos', 'naves', 'avion'); 

foreach ($apartados as $key) { 
    echo $i18n.$key; 

} 

을 결합, foreach는에서 변수를 만들려고하고 있지만, 예상되는 결과는 다음

$i18ncoches 
$i18nmotos 

을두고 있지만, 다음을 얻을 수 있습니다 알림 : 정의되지 않은 변수 : i18n

coches motos etc,,, 

답변

1

이런 식으로 할 수 있습니다 :

<?php 

    $i18ncoches="coches"; 
    $i18nmotos="motos"; 

    $apartados=array('coches', 'motos', 'naves', 'avion'); 

    foreach ($apartados as $key) { 

     // if(isset(${'i18n'.$key})) //you will need this check 
      echo ${'i18n'.$key}; 

    } 

?> 
+0

고마워요. – Cazs

관련 문제