0

こんにちは、すべて私はphpに新しく、スタックオーバーフローには新しいですが、phpについてある程度の知識があります。私がやろうとしているのは、API関数から返された配列呼び出しから1つの値を取得することです

$character->getSlot('head');

print_r を使用すると、次のようになります。

Array ( 
[icon] => http://url to image location
[name] => Wizard's Petasos 
[slot] => head )

$character->getSlot('head', 'name); をエコーする場合 19行目に C:\xampp\htdocs\test\index.php が表示され、 Array という単語が返されます

これがindex.phpのセクションです

<?php
include('api.php');

// Call API
$API = new LodestoneAPI();

// Search for: Demonic Pagan on Sargatanas
$character = $API->get(array(
"name" => "Darka Munday",
"server" => "Ragnarok"
));

// Basic character data
echo "Character ID: " . $character->getID(); 
$ID = $character->getID();
$API->parseProfile($ID);
$Character = $API->getCharacterByID($ID);
echo $character->getSlot('head', 'name');

念のため、APIのセクション

// GEAR
public function setGear($Array)
{
$this->Gear['slots'] = count($Array);
$GearArray = NULL;

// Loop through gear equipped
    $Main = NULL;
                    foreach($Array as $A)
            {
                // Temp array
                $Temp = array();

                // Loop through data
                $i = 0;
                foreach($A as $Line)
                {
                        // Item Icon
                        if (stripos($Line, 'socket_64') !== false) { $Data = trim(explode('&quot;', $A[$i + 1])[1]); $Temp['icon'] = $Data; }
                        if (stripos($Line, 'item_name') !== false) { $Data = trim(str_ireplace(array('>', '"'), NULL, strip_tags(html_entity_decode($A[$i + 2])))); $Temp['name'] = htmlspecialchars_decode(trim($Data), ENT_QUOTES); }
                        if (stripos($Line, 'item_name') !== false) {
                        $Data = htmlspecialchars_decode(trim(html_entity_decode($A[$i + 3])), ENT_QUOTES);
                        if (
                                strpos($Data, " Arm") !== false ||
                                strpos($Data, " Grimoire") !== false ||
                                strpos($Data, " Tool") !== false
                                        )
                                        { $Main = $Data; $Data = 'Main'; }
                    $Temp['slot'] = strtolower($Data);
                                }

                                // Increment
                                $i++;
            }

            // Slot manipulation
                                $Slot = $Temp['slot'];
                                    if (isset($GearArray[$Slot])) { $Slot = $Slot . 2; }

                                    // Append array
                                    $GearArray['numbers'][] = $Temp;
                                    $GearArray['slots'][$Slot] = $Temp;
                                    }

                                    // Set Gear
                                    $this->Gear['equipped'] = $GearArray;

                                    // Set Active Class
                                    $classjob = str_ireplace('Two-Handed ', NULL, explode("'", $Main)[0]);
                                    $this->Stats['active']['class'] = $classjob;
                                    if (isset($this->Gear['soul crystal'])) { $this->Stats['active']['job'] = str_ireplace("Soul of the ", NULL, $this->Gear['soul crystal']['name']); }
                                    }
                                    public function getGear()           { return $this->Gear; }
    public function getEquipped($Type)  { return $this->Gear['equipped'][$Type]; }
    public function getSlot($Slot)      { return $this->Gear['equipped']['slots'][$Slot]; }

これに対する解決策はおそらく本当に単純で、私は本当にばかげていますが、どんな助けも素晴らしいでしょう:)事前に感謝します

4

1 に答える 1

3
public function getSlot($Slot) { 
     return $this->Gear['equipped']['slots'][$Slot]; 
}

getSlotメソッドの引数は 1 つだけです。別の引数を渡していますが、getSlotメソッドは配列を返します。

あなたはこのようにすることができます:

public function getSlot($Slot, $param = null) {
    if(empty($param)) {
          return $this->Gear['equipped']['slots'][$Slot]; 
    } else {
        if(isset($this->Gear['equipped']['slots'][$Slot][$param] )) {
            return $this->Gear['equipped']['slots'][$Slot][$param];
        } else {
            return null;
        }
    }     
}

また

echo $character->getSlot('head')['name'] // If version is >= 5.4.*

バージョン < 5.4.* の場合

$slot = $character->getSlot('head');
echo $slot['name'];
于 2013-09-06T12:35:37.490 に答える