【问题标题】:how to read values from an assosiative array using php?如何使用 php 从关联数组中读取值?
【发布时间】:2017-11-30 15:17:12
【问题描述】:

这是我的示例关联数组:

Array (
    [0] => Array (
        [Name] => ALCOIN
        [BasePlugin] => HTTP
        [Version] => 1
        [Description] => Plugin for ALCO_IN operations
        [ImagePath] => ./resources
        [xip] => http://www.example.org/XIP
        [xsi] => http://www.w3.org/2001/XMLSchema-instance
        [schemaLocation] => http://www.example.org/XIP XIP.xsd
    )
    [1] => Array (
        [xip:Action] => Array (
            [@attributes] => Array (
                [Name] => OfferActivationByOfferID
                [Version] => 1.0
                [ImagePath] => ./resources
            )
        )
    )
)

在该数组中,我需要获取 BasePlugin 值和名称 attribute 值。

【问题讨论】:

标签: php arrays


【解决方案1】:

看来你可能需要这个:

$basePlugin = $yourArray[0]['BasePlugin'];
$attributes = $yourArray[1]['xip:Action']['@attributes'];

【讨论】:

    【解决方案2】:

    假设你被分配到$yourVar 喜欢:

    $yourVar = Array (
        [0] => Array (
            [Name] => ALCOIN
            [BasePlugin] => HTTP
            [Version] => 1
            [Description] => Plugin for ALCO_IN operations
            [ImagePath] => ./resources
            [xip] => http://www.example.org/XIP
            [xsi] => http://www.w3.org/2001/XMLSchema-instance
            [schemaLocation] => http://www.example.org/XIP XIP.xsd
        )
        [1] => Array (
            [xip:Action] => Array (
                [@attributes] => Array (
                    [Name] => OfferActivationByOfferID
                    [Version] => 1.0
                    [ImagePath] => ./resources
                )
            )
        )
    )
    

    你会使用:

    echo $yourVar[0]["BasePlugin"];
    echo $yourVar[1]["xip:Action"]["@attributes"]["Name"];
    echo $yourVar[1]["xip:Action"]["@attributes"]["Version"];
    echo $yourVar[1]["xip:Action"]["@attributes"]["ImagePath"];
    

    【讨论】:

      猜你喜欢
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 2012-10-19
      相关资源
      最近更新 更多