728x90
$object = new User; // new 키워드로 User 객체를 생성한다.

class User{ // User 클래스 선언

public $id = "test", $email, $name, $birthday; //public으로 변수 선언

function printUser(){ // User 클래스에 printUser 메소드 선언
print_r($this); // User 클래스 Print
}
}

// 객체 내 속성 접근 시에는 -> 사용하며 속성명 앞엔 $ 붙이지 않는다.
if ($object -> id === 'test' ) {
echo $object -> id;
//console.log(json_encode($object));
} else {
echo 'tt';
}

객체 배열 접근

if ($obj['id'] === 'testid') {
	( ...)
}

JSON 객체 변환

<!DOCTYPE html>
<html>
<body>

<?php

$postData = '{"eventType":"PAYMENT_STATUS_CHANGED","data":{"paymentKey":"kWzn16mywdYPBal2vxj81gvOa0ORAV5RQgOAND7pJe9KE0qL","status":"DONE","orderId":"CDD-7A7VCXTN"}}';
$json = (array)json_decode($postData);
echo $json['data']->orderId;

//echo substr("Hello world",6);
?>

</body>
</html>

 

php에서 콘솔 로그 찍기

function debug_to_console($data) {
    $output = $data;
    if (is_array($output))
        $output = implode(',', $output);

    echo "<script>console.log('Debug Objects: " . json_encode($output) . "' );</script>";
}

usage : 

debug_to_console($object->id);

+ Recent posts