私はこの配列を持っています:
[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
)
)
この配列を [tags] でソートしたいのですが、どうすればこの PHP を実行できますか? オンライン ツール [タグ] を使用して、私のウェブサイトで i want "#1", "#2" で注文します。
しかし、私は [タグ] のように「#1」と「カテゴリ」よりも 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;
}
しかし、この SORT by ALL では、NAME と次の NUMBER の後に EMPTY が導入されます
[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
)
)
ありがとう