将 link 添加到 json 的每个元素

Add link to each element of json

我有显示玩家 Steam 库存的代码,代码:

<?php
    function recursiveFind(array $array, $needle)
    {
        $iterator  = new RecursiveArrayIterator($array);
        $recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
        $aHitList = array();
        foreach ($recursive as $key => $value) {
            if ($key === $needle) {
                array_push($aHitList, $value);
            }
        }
        return $aHitList;
    }

    $id = $_GET["id"];
    $link = file_get_contents('http://steamcommunity.com/id/'.$id.'/inventory/json/730/2');
    $link = json_decode($link, true);

    $name = recursiveFind($link, "market_hash_name");
    $csv = implode('<br />', array_values($name));

    echo '<b>Total: </b>';
    echo count($name);
    echo '<br />';

    #echo '<a href="http://steamcommunity.com/market/listings/730/'.$csv.'" />';
    echo $csv;
   # echo '</a>';
?>

示例输出:

Total: 9
Glock-18 | Water Elemental (Field-Tested)
P250 | Supernova (Factory New)
StatTrak™ AK-47 | Elite Build (Field-Tested)
AWP | Worm God (Field-Tested)
M4A4 | Urban DDPAT (Field-Tested)
UMP-45 | Urban DDPAT (Field-Tested)
MAC-10 | Urban DDPAT (Field-Tested)
Desert Eagle | Urban DDPAT (Field-Tested)
Tec-9 | Urban DDPAT (Field-Tested)

我想向每个元素添加一个 href link,它以“http://steamcommunity.com/market/listings/730/HERE EACH ELEMENT OF JSON

我该怎么做?

替换以下内容:

  // ...
 $name = recursiveFind($link, "market_hash_name");
 foreach($item in $name){
     echo $item;
     echo '<a href="http://steamcommunity.com/market/listings/730/' . urlencode($item) . '" />';
     echo "<br/>";
 }
 echo '<b>Total: </b>';
 echo count($name);
 echo '<br />';