Header Ads

PHP 함수와 클래스의 기본


$a = 100;
$b = 10;
$c = 1;

/* Call by Value */

// Return One Value
function method1($a, $b)
{
 $c = $a + $b;
 return $c;
}
echo " function1 = " . method1($a,$b);

// Return Some Value
function method2($a, $b, $c)
{
 $a++;
 $b++;
 $c++;
 return array($a,$b,$c);
}
list($x,$y,$z) = method2($a,$b,$c);
echo " function2 = $x / $y / $z ";

/* Call by Reference */
function foo(&$str)
{
 $str .= "world";
}

function swap(&$a,&$b)
{
 $temp = $b;
 $b = $a;
 $a = $temp;
}

echo "\$a=" . $a . " \$b=" . $b;
swap($a,$b);
echo "\$a=" . $a . " \$b=" . $b;
$str = "hello~ ";
echo $str;
foo($str);
echo $str;

/* Class */
class Class1
{
      function method1()
      {
                echo __FUNCTION__;
      }
      function method2()
      {
                echo __METHOD__;
      }
}
$obj = new Class1();
$obj->method1();
$obj->method2();

No comments

Copyright 2016, minki. All rights reserved. Powered by Blogger.