Re: [請益] 一個簡單的程式問題^^"

看板PHP作者 (IWH68S0XZ8M89)時間16年前 (2008/01/25 14:53), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《icedesign (不可或缺的咖啡因)》之銘言: : ^^" 不好意思,小弟是PHP新手,想請教版上前輩一個簡單的問題。 : 我做了一個練習題目,如下: : <?PHP : for($i=0;$i<5;$i++){ : $myArray = array( : 'LL', : 'GG', : 'HH', : 'WW', : 'II'); : extract($myArray,EXTR_PREFIX_ALL,"newArray"); : echo "$newArray"._."$i"."<br/>"; : } : ?> : 結果印出來的是 : newArray_0 : newArray_1 : newArray_2 : newArray_3 : newArray_4 : 而不是我所想要的陣列內的值,請問版上前輩,應該要怎麼寫才對呢? : 謝謝各位。 你要的應該是這樣: $arr=array('hello','world','XD','orz','QQ'); extract($arr,EXTR_PREFIX_ALL,"elem"); for($i=0; $i<5; $i++) { $s="elem_".$i; echo "$$s"."<br />"; } 利用""的字串取代 把$s放入變數名稱 再加一層$去取它 -- 'Oh, Harry, dont't you see?' Hermione breathed. 'If she could have done one thing to make absolutely sure that every single person in this school will read your interview, it was banning it!' ---'Harry Potter and the order of the phoenix', P513 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.84.44.21

01/25 15:25, , 1F
謝謝!
01/25 15:25, 1F
文章代碼(AID): #17cOT__6 (PHP)
文章代碼(AID): #17cOT__6 (PHP)