我有這樣的陣列:排序PHP多維數組[值1] [值]
[0] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => MusicVideos, #20
)
)
[1] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => MusicVideos, #5
)
)
[2] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => #9, MusicVideos
)
)
[3] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => #12, MusicVideos
)
)
現在我想排序這個數組通過[標籤]我如何做到這一點這個PHP? 使用在線工具[標籤]用在我的網站上訂購的,我想「#1」,「2號」
但我有比[標籤]象「#1」和「類別」
一個更[Tags] => #1 [Tags] => MusicVideos, #2 [Tags] => #3
是否有可能這樣?
我嘗試使用此功能:
function msort($array, $key, $sort_flags = SORT_NUMERIC) {
if (is_array($array) && count($array) > 0) {
if (!empty($key)) {
$mapping = array();
foreach ($array as $k => $v) {
$sort_key = '';
if (!is_array($key)) {
$sort_key = $v[$key];
} else {
// @TODO This should be fixed, now it will be sorted as string
foreach ($key as $key_key) {
$sort_key .= $v[$key_key];
}
$sort_flags = SORT_STRING;
}
$mapping[$k] = $sort_key;
}
asort($mapping, $sort_flags);
$sorted = array();
foreach ($mapping as $k => $v) {
$sorted[] = $array[$k];
}
return $sorted;
}
}
return $array;
}
但是,這種由所有名稱和下一個號碼
[0] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => #5
)
)
[1] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => Commercials, #3
)
)
[2] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => Commercials, #9
)
)
[3] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => MusicVideos, #1
)
)
[4] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => MusicVideos, #10
)
)
後引進空的,我想是這樣的:
[0] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => MusicVideos, #1
)
)
[1] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => Commercials, #3
)
)
[2] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => #5
)
)
[3] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => Commercials, #9
)
)
[4] => Array
(
[tags] => SimpleXMLElement Object
(
[0] => MusicVideos, #10
)
)
謝謝
是標籤本身(在「標籤'字段)已經按排序順序?即我會找到包含「MusicVideos,#5」的'tags'字段嗎?如果是這樣''MusicVideos,#5'在#12之前排序,MusicVideos? –
我使用VIMEO API,有時他們有時不排序或更改標籤的順序。 如果可能,我想要搜索數組在哪裏(「#1」,「#2」)並按順序排列,有可能嗎? – diogoroseiro
你可以使用[array_multisort()](http://php.net/manual/en/function.array-multisort.php#example-4927),我不明白你想排序 –