0

Q:如何在海量多维数组中查找单值,并返回父数组?

我有这个巨大的 json,它代表了《魔兽世界》中的所有成就。

http://us.battle.net/api/wow/data/character/achievements

我使用 json_decode 将其转换为数组。这给我留下了一个非常庞大的数组,我需要搜索它的所有级别,直到找到一个特定的值,然后我需要返回该值的父数组。

前任:

这是解码数组的一小部分。

[0] => Array
(
[id] => 7385
[title] => Pub Crawl
            [points] => 10
            [description] => Complete the Brewmaster scenario achievements listed below.
            [reward] => Reward: Honorary Brewmaster Keg
            [rewardItems] => Array
                (
                    [0] => Array
                        (
                            [id] => 87528
                            [name] => Honorary Brewmaster Keg
                            [icon] => inv_holiday_brewfestbuff_01
                            [quality] => 3
                            [itemLevel] => 90
                            [tooltipParams] => Array
                                (
                                )

                            [stats] => Array
                                (
                                )

                            [armor] => 0
                        )

                )

            [icon] => inv_misc_archaeology_vrykuldrinkinghorn
            [criteria] => Array
                (
                    [0] => Array
                        (
                            [id] => 20680
                            [description] => Spell No Evil
                            [orderIndex] => 0
                            [max] => 1
                        )

                    [1] => Array
                        (
                            [id] => 20681
                            [description] => Yaungolian Barbecue
                            [orderIndex] => 1
                            [max] => 1
                        )

                    [2] => Array
                        (
                            [id] => 20682
                            [description] => Binan Village All-Star
                            [orderIndex] => 2
                            [max] => 1
                        )

                    [3] => Array
                        (
                            [id] => 20683
                            [description] => The Keg Runner
                            [orderIndex] => 3
                            [max] => 1
                        )

                    [4] => Array
                        (
                            [id] => 20684
                            [description] => Monkey in the Middle
                            [orderIndex] => 4
                            [max] => 1
                        )

                    [5] => Array
                        (
                            [id] => 20685
                            [description] => Monkey See, Monkey Kill
                            [orderIndex] => 5
                            [max] => 1
                        )

                    [6] => Array
                        (
                            [id] => 20686
                            [description] => Don't Shake the Keg
                            [orderIndex] => 6
                            [max] => 1
                        )

                    [7] => Array
                        (
                            [id] => 20687
                            [description] => Party of Six
                            [orderIndex] => 7
                            [max] => 1
                        )

                    [8] => Array
                        (
                            [id] => 20688
                            [description] => The Perfect Pour
                            [orderIndex] => 8
                            [max] => 1
                        )

                    [9] => Array
                        ( re
                            [id] => 20689
                            [description] => Save it for Later
                            [orderIndex] => 9
                            [max] => 1
                        )

                    [10] => Array
                        (
                            [id] => 20690
                            [description] => Perfect Delivery
                            [orderIndex] => 10
                            [max] => 1
                        )

                )

            [accountWide] => 
            [factionId] => 2
        )

我正在尝试创建一个函数,我可以在其中简单地输入成就 ID,在此示例中为7385,并具有将 [0] => Array (...);返回的父数组,因此我可以从该数组中获取成就详细信息。

我不确定这是否真的是一个正确的问题,因为我不确定从哪里开始。

到目前为止,我刚刚开始将原始的海量数组分解为 10 个同样庞大的类别,然后单独搜索它们,但我希望能够只搜索一次主数组,而不是单独搜索每个类别数组。

前任:

$allAchieves = file_get_contents('http://us.battle.net/api/wow/data/character/achievements');
$allAchieves = json_decode($allAchieves, true);

$generalAchieves = $allAchieves[achievements][0][achievements];
$quests = $allAchieves[achievements][1][categories];
$explorationAchieves = $allAchieves[achievements][2][categories];
$pvp = $allAchieves[achievements][3][categories];
$dungeonAndRaids = $allAchieves[achievements][4][categories];
$professions = $allAchieves[achievements][5][categories];
$reputation = $allAchieves[achievements][6][categories];
$scenarios = $allAchieves[achievements][7][categories];
$worldEvents = $allAchieves[achievements][8][categories];
$petbattle = $allAchieves[achievements][9][categories];
$featsOfStrength = $allAchieves[achievements][10][categories];

希望有人可以提供帮助,因为到目前为止我在数组搜索方面看到的其他线程似乎太简单而无法提供任何帮助,因为他们正在处理的数组与我在这里的数组大小无关。

4

1 回答 1

0

感谢您的建议,但我使用此处找到的不同方法解决了该问题: http ://us.battle.net/wow/en/forum/topic/8892160022?page=1#4

于 2013-05-28T20:26:09.943 回答