[PHP] PHP 기초
Nowhere 와 Now here 의 차이

IT/ㄴ PHP

[PHP] PHP 기초

TIENE 2023. 8. 28. 08:13
반응형

- php 는 대체로 Linux Shell Script와 비슷한 구조의 프로그래밍이다. Linux Shell Script를 할 줄 안다면 금방 적응할 수 있다. 그래도 어려운 건 매한가지다...

 

[Linux] Shell Script 기초 [echo]

 

[Linux] Shell Script 기초 [echo]

개요 - 셀은 사용자가 입력한 명령을 해석하고 커널에서 전달하고, 처리 결과를 반대로 사용자에게 전달하는 역할을 한다. - 텍스트 모드나 터미널 처럼 명령어를 입력하는 환경이이 셸이라고

a-gyuuuu.tistory.com

 

 

[Linux] Shell Script - if 문 기초 [if / else / 비교 연산자]

 

[Linux] Shell Script - if 문 기초 [if / else / 비교 연산자]

if문 (1) 기본 if문 - 대부분의 프로그래밍 언어에서 사용된다. - 영단어 if 뜻 그대로 [만약에 어떠한 조건이 참이면 실행] 하는 명령문이다. - 주의해야 할점은 [ 조건 ] 사이의 각 단어에는 모두 공

a-gyuuuu.tistory.com

 

 

[Linux] Shell Script - 다중 if 문 / case 문 / 파일 연산자 [ elif/ case]

 

[Linux] Shell Script - 다중 if 문 / case 문 / 파일 연산자 [ elif/ case]

다중 if 문 - if 문을 다중으로 사용하는 문구다. - elif를 사용하여 if 문을 다중으로 사용가능하다. - 평균이 90 점이상이면 A학점, 80점 이상이면 B학점 70 점이상이면 C학점 그 미만은 F학점을 출력

a-gyuuuu.tistory.com

 

 

[Linux] Shell Script - 반복문 [ while / for ]

 

[Linux] Shell Script - 반복문 [ while / for ]

while문 - while문은 조건식이 참일 동안에 계속 반복하는 특성을 갖는다. - 조건이 만족할 때까지 반복한다. - 무한루프에서 5번 반복 후 while 문을 중지한다. 두 가지 반복문으로 가능하다. #! /bin/sh

a-gyuuuu.tistory.com


<br> 차이

- php안에서도 html 언어를 사용할 있다.

<br> 의 차이

$id="admin"; $pw="1234";
if($id=="admin" and $pw=="1234") {
echo "$id 로그인 성공";
}
else {
echo $id,"로그인 실패";
}
?>

<?php
//DB 연결 검증
$con=mysqli_connect("localhost","root","1234") or die("MariaDB 연결 실패");
echo "DB 연결 성공";
mysqli_close($con);
?>

 

<?php
//DB 연결 검증
$con=mysqli_connect("localhost","root","1231") or die("MariaDB 연결 실패");
echo "DB 연결 성공";
mysqli_close($con);
?>

- 변수 이름은 숫자로 시작 못하는 것을 이제 알았다...

The code you provided seems almost correct, but there is an issue with the variable name `$34hap`. Variable names in programming languages must start with a letter or underscore, followed by letters, underscores, or digits. They cannot start with a number. In your case, `$34hap` starts with a number, which is not allowed.

Here's the corrected version of the code with the variable name fixed:


$even = 0;
$odd = 0;
$hap34 = 0;  // Changed variable name to $hap34

for ($i = 1; $i <= 100; $i++) {
    if ($i % 2 == 0) {
        $even = $even + $i;
    } else {
        $odd = $odd + $i;
    }
    if ($i % 3 == 0 or $i % 4 == 0) {
        $hap34 = $hap34 + $i;  // Updated variable name here
    }
}
echo "1부터 100까지의 홀수의 합 : $odd <br>", "1부터 100까지의 짝수의 합 : $even";
echo "1부터 100까지의 3 또는 4의 배수의 합 : ", $hap34;


Now the variable name `$hap34` follows the correct naming convention and should work without any issues.

 

 

반응형

'IT > ㄴ PHP' 카테고리의 다른 글

[CentOS] PHP 연습 환경 구축하기  (0) 2023.08.25