0
我使用var_dump($ fields)來輸出下面的PHP數組;將具有匹配鍵值的數組移動到新的分組數組
array() {
[ 0 ] => array() {
[ "state" ] => string(3) "nsw"
[ "address" ] => string(13) "8 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
[ 1 ] => array() {
[ "state" ] => string(2) "wa"
[ "address" ] => string(13) "5 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
[ 2 ] => array() {
[ "state" ] => string(3) "qld"
[ "address" ] => string(13) "3 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
[ 3 ] => array() {
[ "state" ] => string(3) "nsw"
[ "address" ] => string(13) "1 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
}
我想從所有的「狀態」鍵創建新陣列呈現在$字段和對應的值以上,從而其像下面移動。
array() {
[ "nsw" ] => array() {
[0] => array() {
[ "address" ] => string(13) "8 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
[1] => array() {
[ "address" ] => string(13) "1 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
}
[ "wa" ] => array() {
[0] => array() {
[ "address" ] => string(13) "5 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
}
[ "qld" ] => array() {
[0] => array() {
[ "address" ] => string(13) "3 Test Street"
[ "phone" ] => string(12) "0000 000 000"
[ "email" ] => string(15) "[email protected]"
}
}
}
任何人都可以請大家幫忙,一直在尋找這個答案沒有運氣。
謝謝!
謝謝亞歷山大!非常感激。 –