function my($array){
while($pointer = current($array)){
return $pointer;
next($array);
}
}
$myArray =[1,2,3];
$showValues = my($myArray);
echo $showValues;
//I only get the first element back
//When I use echo it works fine
答案 0 :(得分:0)
答案 1 :(得分:0)
你有几个选项,标准方法是只返回一个数组而不是一个值,另一个是通过passing by reference创建一个新数组,所以从技术上讲你不会返回任何内容,但结果是类似(数组):
// Return an array
function my($array)
{
foreach($array as $key => $value)
$row[$key] = $value;
return $row;
}
// Pass by reference
function myPass($array,&$new)
{
foreach($array as $key => $value)
$new[$key] = $value;
}
返回一个数组:
$myArray = array(1,2,3);
$notRef = my($myArray);
print_r($notRef);
通过引用传递:
$myArray = array(1,2,3);
$new = array();
myPass($myArray,$new);
print_r($new);
给你(双向):
Array
(
[0] => 1
[1] => 2
[2] => 3
)