PHP3���IJο��ֲ� ���ķ��룺Sadly [email protected] http://wansoft.soim.net | ||
---|---|---|
��һҳ | �����»������ | ��һҳ |
����ͨ�����µ�����庯��:
function foo( $arg_1, $arg_2, ..., $arg_n ) { echo "Example function.\n"; return $retval; }
�����п���ʹ���κ���Ч��PHP3 ���룬�����������ĺ������� �Ķ���
��������ͨ����ѡ��return��䷵��ֵ������ֵ�������κ����ͣ������б��Ͷ���
function my_sqrt( $num ) { return $num * $num; } echo my_sqrt( 4 ); // outputs '16'.
��������ͬʱ���ض��ֵ,������ͨ�������б��ķ�����ʵ��:
function foo() { return array( 0, 1, 2 ); } list( $zero, $one, $two ) = foo();
�ⲿ��Ϣ����ͨ�������������뺯���У�����������һϵ�ж��ŷָ��ı�����/������
PHP3֧��ͨ��ֵ�β�����Ĭ�ϣ�, ��������,�� Ĭ�ϲ�������֧�ֱ䳤������, �������ô�������ķ�����ʵ�֡�
Ĭ��������������Ǵ�ֵ��ʽ����������������Ĵ��������ֵ,�����ʹ�ñ���������
�����ϣ��������һ����ʽ����ʼ���DZ�������,������ں�������ʱ������ʽ������(&)ǰ:
function foo( &$bar ) { $bar .= ' and something extra.'; } $str = 'This is a string, '; foo( $str ); echo $str; // outputs 'This is a string, and something extra.'
���Ҫ����һ���ɱ������Ĭ�ϵ���ʽ�������DZ�η�ʽ�ĺ���,������ڵ��ú���ʱ��ʵ�ʲ�����(&)ǰ:
function foo( $bar ) { $bar .= ' and something extra.'; } $str = 'This is a string, '; foo( $str ); echo $str; // outputs 'This is a string, ' foo( &$str ); echo $str; // outputs 'This is a string, and something extra.'
�������Զ��� C++ ����Ĭ��ֵ������:
function makecoffee( $type = "cappucino" ) { echo "Making a cup of $type.\n"; } echo makecoffee(); echo makecoffee( "espresso" );
�ϱ���δ���������:
Making a cup of cappucino. Making a cup of espresso.
ע�⣬��ʹ��Ĭ�ϲ���ʱ������Ĭ��ֵ�IJ���Ӧ����Ĭ��ֵ�IJ����ĺ�߶���;�������ᰴ��������������������������Ƭ��:
function makeyogurt( $type = "acidophilus", $flavour ) { return "Making a bowl of $type $flavour.\n"; } echo makeyogurt( "raspberry" ); // won't work as expected
������ӵ���������:
Warning: Missing argument 2 in call to makeyogurt() in /usr/local/etc/httpd/htdocs/php3test/functest.html on line 41 Making a bowl of raspberry .
������������������Ƚ����º���:
function makeyogurt( $flavour, $type = "acidophilus" ) { return "Making a bowl of $type $flavour.\n"; } echo makeyogurt( "raspberry" ); // works as expected
��������������:
Making a bowl of acidophilus raspberry.