php中怎样自定义函数改变数组的值?
为什么这样写改变不了呢?$table_exchange=array(1,2,3,4,5,6,7,8);NumChange($table_exchange);functio...
为什么这样写改变不了呢?
$table_exchange=array(1,2,3,4,5,6,7,8);
NumChange($table_exchange);
function NumChange($num){
foreach ($num as $b=>$c){
$num[$b]="Week_".$c;
}
}
echo $table_exchange[0];
求指教~ 展开
$table_exchange=array(1,2,3,4,5,6,7,8);
NumChange($table_exchange);
function NumChange($num){
foreach ($num as $b=>$c){
$num[$b]="Week_".$c;
}
}
echo $table_exchange[0];
求指教~ 展开
1个回答
展开全部
传引用即可,例子代码:
<?php
$table_exchange=array(1,2,3,4,5,6,7,8);
NumChange($table_exchange);
print_r($table_exchange);
echo $table_exchange[0];
function NumChange(&$num){
foreach ($num as $b=>$c){
$num[$b]="Week_".$c;
}
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询