몇 가지 건설적인 비판을 준비하십시오.
이 코드에는 많은 문제가 있습니다. 먼저 실수를 설명하는 주석과 아무것도하지 않는 무의미한 것들을 설명하겠습니다. 그런 다음 필요한 것은
$folderPath="".cdnurl."assets/".pid."";
// 1. Single-quotes will perform slightly better.
// 2. There is no need for the first "". or the final ."" - they do nothing.
// 3. Ideal: $folderPath = cdnurl.'assets/'.pid;
// 4. This assumes that cdnurl and pid are constants declared with the define() command. If they are not constants, you need dollar-signs, which would make it:
// $folderPath = $cdnurl.'assets/'.$pid;
$folderSubNumber => 3;
// You cannot put a "more than X" or "less than X" in a variable. The => is used in foreach() loops for a completely different purpose, and when declaring values in an array only when the array is originally declared. (In other words; in this case, this does nothing.)
// Indentation really does matter. This should be indented the same as the code above.
while(file_exists($folderPath.$folderSubNumber)) {
// 1. $folderSubNumber never changes and so this while-loop always asks the exact same question.
// 2. You don't have a directory separator "/", so this will append $folderSubNumber straight to pid, above.
echo '<li><img src="assets/pid/'.folderSubNumber.'';
// 1. folderSubNumber needs a dollar-sign because it's a variable. If it is not defined as a constant, it will simply be the literal string "folderSubNumber".
// 2. The appended .'' does nothing and shouldn't be there.
// 3. You are neither closing the <img> tag, nor the <li> tag, nor in fact the src-attribute.
// 4. Ideal: echo '<li><img src="assets/pid/'.$folderSubNumber.'" /></li>';
} else {
// 1. There is no "else" in while.
// 2. You don't need an "else" if the intention is to do nothing.
echo "";
// This is 100% pointless, it does nothing.
}
, 당신은 동안 루프에서 그것을 시도 한 후 $의 foldeSubNumber를 증가 ('sdleihssirhc'로 답 참조)하는 것입니다. 그러나 $ folderPath와 $ folderSubNumber 사이에 디렉토리 구분자가 필요할 수도 있습니다. 즉 : $folderPath.'/'.$folderSubNumber
행운을 빕니다!
문제가 무엇입니까? – genesis
'() {} else {}','folderSubNumber'는'echo'라인에'$'이 필요하고'$ folderSubNumber => 3;은'$ folderSubNumber = 3;이어야합니다. '('=>'는 배열 키/값에 대해서만 사용됩니다.) –
PHP에는 while() {} else {} 문이 없으므로 else {}를 제거하고 어떤 일이 발생하는지 확인하십시오. – csjohn