本文介绍了HOWTO:全局使用数组? (我希望功能与它一起工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一切;而且我似乎无法通过这个非常好的问题。看起来只是问题。


我想在函数中使用数组变量( s)。


我无法上班;如果我:

1)global $ arr = array(); (语法错误)

2)global $ arr;在main中,var不是全局的

3)global $ arr;在功能上,每次清除数组


我知道我必须遗漏一些非常简单/愚蠢的东西;但只是不能...... b $ b似乎找到了它!任何帮助表示赞赏!

tia - Bob


ei:

<?php

for ($ x = 1; $ x< = 2; $ x ++){

print" \ nloop#$ x\\\
" ;;

if($ x == 1){

$ row [1] =" Why" ;; $行[2] ="那并不英寸; $ row [3] =" this work ??" ;;

$ row [4] =" this does" ;; }

if($ x == 2){

$ row [1] =" This is; $ row [2] =" 2nd the quot ;; $ row [3] =" time thru。";

$ row [4] =" all done" ;; }


print" 123before:1:$ arr [1] 2:$ arr [2] 3:$ arr [3] s:$ s\\\
" ;;

print" 456before:4:$ arr [4] 5:$ arr [5] 6:$ arr [6] s:$ s\ n" ;;

myf ($ x,$ row);

print" 123after:1:$ arr [1] 2:$ arr [2] 3:$ arr [3] s:$ s\\\
" ;

print" 456after:4:$ arr [4] 5:$ arr [5] 6:$ arr [6] s:$ s\ n" ;;

}


函数myf($ x,$ frow){

global $ arr,$ s;

if( $ x == 1){$ arr = array(1 => $ frow [1],2 => $ frow [2],3 => $ frow [3]);

$ s = $ frow [4]; }

if($ x == 2){$ arr = array(4 => $ frow [1],5 => $ frow [2],6 => $ frow [ 3]);

$ s = $ frow [4]; }

print" 123during:1:$ arr [1] 2:$ arr [2] 3:$ arr [3] s:$ s\\\
" ;;

print" 456during:4:$ arr [4] 5:$ arr [5] 6:$ arr [6] s:$ s\ n" ;;

}

?>

解决方案




I''ve tried everything; and I can''t seem to get past this VERY
(seemingly) simply problem.

I want to work with an array variable within a function(s).

I can''t get it to work; if I:
1) global $arr=array(); (syntax err)
2) global $arr; in "main", the var isn''t global
3) global $arr; in function, the array is cleared each time

I know I must be missing something REALLY simple/dumb; but just can''t
seem to find it! any help appreciated!
tia - Bob

ei:
<?php
for ($x=1; $x<=2; $x++) {
print "\nloop # $x\n";
if($x==1) {
$row[1]="Why"; $row[2]="doesn''t"; $row[3]="this work??";
$row[4]="this does"; }
if($x==2) {
$row[1]="This is"; $row[2]="the 2nd"; $row[3]="time thru.";
$row[4]="all done"; }

print "123before: 1:$arr[1] 2:$arr[2] 3:$arr[3] s:$s\n";
print "456before: 4:$arr[4] 5:$arr[5] 6:$arr[6] s:$s\n";
myf($x,$row);
print "123after : 1:$arr[1] 2:$arr[2] 3:$arr[3] s:$s\n";
print "456after : 4:$arr[4] 5:$arr[5] 6:$arr[6] s:$s\n";
}

function myf($x,$frow) {
global $arr, $s;
if ($x==1) { $arr=array(1=>$frow[1],2=>$frow[2],3=>$frow[3]);
$s=$frow[4]; }
if ($x==2) { $arr=array(4=>$frow[1],5=>$frow[2],6=>$frow[3]);
$s=$frow[4]; }
print "123during: 1:$arr[1] 2:$arr[2] 3:$arr[3] s:$s\n";
print "456during: 4:$arr[4] 5:$arr[5] 6:$arr[6] s:$s\n";
}
?>

解决方案




这篇关于HOWTO:全局使用数组? (我希望功能与它一起工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 00:04