Re: [請益] 陣列的問題

看板PHP作者 ((short)(-15074))時間17年前 (2008/12/01 15:38), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《bellboy (鈴鐺人)》之銘言: : 請問大家 : 假設我有一個二維陣列如下: : Array : ( : [0] => Array : ( : [id] => 1 : [status] => 'aaa' : ) : [1] => Array : ( : [id] => 2 : [status] => 'bbb' : ) : [2] => Array : ( : [id] => 3 : [status] => 'ccc' : ) : ) : 我想要把這個陣列變成: : Array : ( : [0] => 'aaa' : [1] => 'bbb' : [2] => 'ccc' : ) : 除了丟進迴圈一個一個轉之外,是不是有比較快的方法呢? : 感謝! 其實丟迴圈也沒那麼繁啊: foreach ($array as &$value) { $value=$value['status']; } unset($value); 最後一行的用意是因為foreach完之後 $value 會參考到陣列的最後一個元素 即使跳出迴圈了一樣還在 所以建議是用unset把它處理掉 避免之後用 $value 時出現意外狀況 -- '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: 140.112.30.84

12/01 16:28, , 1F
感謝!
12/01 16:28, 1F
文章代碼(AID): #19CvH-Vs (PHP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #19CvH-Vs (PHP)