-1
정의되지 않은 변수로 문자열을 처리 할 수있는 클래스를 만들려고합니다. 이것이 가능한가? 또는 더 좋은 방법이 있습니까? 나는 다음과 변수 $str_1
출력 받아이 클래스 루퍼 싶습니다 $fname
및 $lname
가 작성이있는 경우 예를 들어
, ... 다음 다른 곳에서 나는 루퍼 클래스 및 프로세스 $str_2
를 다시 사용할 수 있기 때문에 둘 다 $fname
필요 및 $lname
.PHP 클래스가 정의되지 않은 변수를 전달합니다.
class Looper {
public function processLoop($str){
$s='';
$i=0;
while ($i < 4){
$fname = 'f' . $i;
$lname = 'l' . $i;
$s .= $str . '<br />';
$i++;
}
return $s;
}
}
$str_1 = "First Name: $fname, Last Name: $lname";
$rl = new Looper;
print $rl->processLoop($str_1);
$str_2 = "Lorem Ipsum $fname $lname is simply dummy text of the printing and typesetting industry";
print $rl->processLoop($str_2);