<?php
function results($string)
{
$result = array();
$result[] = $string;//原字符串
$result[] = strtoupper($string);//全部换成大写
$result[] = strtolower($string);//全部换成小写
$result[] = ucwords($string);//单词的首字母换成大写
return $result;
}
$multi_result = results('the quick brown fox jump over the lazy dog');
print_r($multi_result);
?>
输出结果:
array
(
[0] => the quick brown fox jump over the lazy dog
[1] => the quick brown fox jump over the lazy dog
[2] => the quick brown fox jump over the lazy dog
[3] => the quick brown fox jump over the lazy dog
)
以上的代码创建了一个$result数组,然后把处理完毕并等待输出的值添加到$result中作为一个元素,最后把$result输出,这样做就实现了自定义函数返回多个值的目的。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!