str_replace, str_replace 또는 다른 옵션을 사용하지 않는 것이 가장 좋습니다.str_replace, str_replace 또는 다른 옵션을 사용하지 않는 것이 가장 좋습니다.
예를 들어 XML 파일을 기반으로 PHP에서 생성 된 배열이 비어 있으며 변경이 필요한 변수가 있습니다. 값이 배열에 있고 변수에 표준 값이 있으면 값을 다른 값 (번역, 다른 단어 등)으로 변경해야합니다.
나는 아래의 코드로이 작업을 수행 할 수 있습니다
<?php
$ethnic_later = 'niet opgegeven';
$ethnic_array = array( 'Blank',
'getint',
'Aziatisch',
'Zuid-Amerikaans'
);
if (in_array('Blank', $ethnic_array) && $ethnic == 'Blank'){
$ethnic = str_replace($ethnic, 'blanke', $ethnic);
}elseif (in_array('getint', $ethnic_array) && $ethnic == 'getint'){
$ethnic = str_replace($ethnic, 'getinte', $ethnic);
}elseif (in_array('Aziatisch', $ethnic_array) && $ethnic == 'Aziatisch'){
$ethnic = str_replace($ethnic, 'Aziatische', $ethnic);
}elseif(in_array($ethnic, $ethnic_array) && $ethnic == 'Zuid-Amerikaans'){
$ethnic = str_replace($ethnic, 'Zuid Amerikaanse', $ethnic);
}else{
$ethnic = str_replace($ethnic, $ethnic_later, $ethnic);
}
echo 'een mooie ' . $ethnic . ' kleur';
?>
아니면 그냥 아래와 같이 PHP 함수 str_replace()
를 사용하지 않고 $ethnic
의 값을 덮어 쓸 수 있습니다 : 더 가능성이있다
<?php
$ethnic_later = 'niet opgegeven';
$ethnic_array = array( 'Blank',
'getint',
'Aziatisch',
'Zuid-Amerikaans'
);
if (in_array('Blank', $ethnic_array) && $ethnic == 'Blank'){
$ethnic = 'blanke';
}elseif (in_array('getint', $ethnic_array) && $ethnic == 'getint'){
$ethnic = 'getinte';
}elseif (in_array('Aziatisch', $ethnic_array) && $ethnic == 'Aziatisch'){
$ethnic = 'Aziatische';
}elseif(in_array($ethnic, $ethnic_array) && $ethnic == 'Zuid-Amerikaans'){
$ethnic = 'Zuid Amerikaanse';
}else{
$ethnic = $ethnic_later;
}
echo 'een mooie ' . $ethnic . ' kleur';
?>
이 일을 이런 식으로하면 위의 2 게시 ... str_replace()
사용하지 않고 마지막 옵션을 사용하여보다 빠른 것입니다 str_replace()
...
질문 :
PHP
을 사용하여 원하는 작업을 수행하는 가장 좋은 방법은 무엇이며 어떻게 이러한 종류의 작업을 수행합니까?
'White', 'Black', 'Yellow'' ftfy – user2176127
@ user2176127 예, 배열을 만드는 또 다른 방법은 읽기 쉽지 않지만'array'('White', 'Black', 'Yellow ');'빨리? – jagb