-> 와 =>의 차이점
-> (= Object Operator)
객체 범위 내에서 객체에 접근하기 위해서 사용하는 오퍼레이터입니다.
=> (= Double Arrow Operator)
배열의 키, 값을 할당할 때 사용하는 오퍼레이터입니다.
사용 예
<?php
$arr1 = array("key1"=>"value1", "key2"=>"value2");
echo arr1["key1"]; // value1
echo arr1["key2"]; // value2
echo arr1->key1; // undefined
echo arr1->key2; // undefined
$obj = (object)$arr1; // array를 object로 형변환하여 사용
echo obj ->key1; // value1
echo obj ->key2; // value2
/* ------------------------------------------------- */
$arr2 = array("key1->"value1"); // error
|
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
|
참고사이트
https://stackoverflow.com/questions/14037290/what-does-this-mean-in-php-or
What Does This Mean in PHP -> or =>
Possible Duplicate: where we use object operator “->” in php Reference - What does this symbol mean in PHP? I see these in PHP all the time but I don't have a clue as to what they actuall...
stackoverflow.com
https://www.php.net/manual/en/language.types.object.php
PHP: Objects - Manual
If you call var_export() on an instance of stdClass, it attempts to export it using ::__set_state(), which, for some reason, is not implemented in stdClass.However, casting an associative array to an object usually produces the same effect (at least, it do
www.php.net
*PHP에서 사용하는 연산자들에 대한 설명을 한 곳에 모아둔 stackoverflow 글 공유합니다.
굉장히 유용할 것 같습니다!
https://stackoverflow.com/questions/14037290/what-does-this-mean-in-php-or
What Does This Mean in PHP -> or =>
Possible Duplicate: where we use object operator “->” in php Reference - What does this symbol mean in PHP? I see these in PHP all the time but I don't have a clue as to what they actuall...
stackoverflow.com