PHP 기초

All We Need is Data, itself !·2022년 1월 17일
0

Backend

목록 보기
1/3

public: 클래스 내 , 클래스 외의 어디에서라도 엑세스 가능
private : 같은 클래스 안에서만 액세스
protected : 같은 클래스 및 자식클래스에서 엑세스

reference: https://samplenara.tistory.com/36


PHP

$arr = array(2,4,6,8);
foreach ($arr as $v) {
echo "변수 \v의 현재값은 {$v}입니다.<br>";
} //escape 동일
unset($v)

PYTHON

arr = array(2,4,6,8)
for i in arr:
print(f"변수 arr의 현재값은 {I}입니다.")

PYTHON DICTIONARY 문법 in PHP

$grades = array('egoing' => 10, 'k8805' => 6);

//call
echo $grades['egoing'];

key : egoing / value : 10
key : k8805 / value : 6

class < className >

**python** : self.__init__(self, var1):
= **php** : function __construct($name, $dong) { ... }

//testUser1 이라는 인스턴스 생성할 때 초기값 전달
$testUser1 = new <className>("init_val1,", "init_val2")

reference: https://devjhs.tistory.com/516


print_r : 변수에 대해 사람이 읽을 수 있는 정보를 출력하는 함수

<?php
$a = array('key1' => 'value1', 'key2' => array('v2_1', 'v2_2') ) ;

print_r ($a);
echo </pre>;
?>

exception

$b = array ('key1' => 'value1', 'key2' => array('v2_1', 'v2_2') );
$results = print_r($b, true); // 로그에 출력하는 경우, value 값 말고

reference: https://extbrain.tistory.com/6



python

class Calculator:
def __init__(self):
self.result = 0

def add(self, num):
self.result += num
return self.result

cal1 = Calculator( )
cal2 = Calculator( )

print(cal1.add(3))
print(cal2.add(4))

print(f"result: {cal1.add(3)}")
accessingCalculator.add( )

reference : https://wikidocs.net/28


PHP5 연산자

http://jun.hansung.ac.kr/SWP/PHP/PHP%20Operators.html


W3 Schools : PHP tutorials

https://www.w3schools.com/php/php_ref_array.asp


PHP manual

https://www.php.net/manual/en/functions.user-defined.php


PHP freeCodeCamp tutorials

https://www.freecodecamp.org/news/the-best-php-examples/


PHP Simple Calculator

https://stackoverflow.com/questions/21445245/simple-php-calculator


PHP5 Variables

http://jun.hansung.ac.kr/SWP/PHP/PHP%205%20Variables.html


여기서 실행연습할 수 있다.

https://www.w3schools.com/php/phptryit.asp?filename=tryphp_var_local


슈퍼전역변수

http://jun.hansung.ac.kr/SWP/PHP/PHP%20Global%20Variables%20-%20Superglobals.html

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
profile
분명히 처음엔 데린이었는데,, 이제 개린이인가..

0개의 댓글