如何使用PHP从关联数组中读取值?

如何使用PHP从关联数组中读取值?

问题描述:

This is my sample associative array:

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
            )
        )
    )
)

In that array I need to get the BasePlugin value and the name attribute value.

这是我的样本关联数组: p>

  Array(\  n [0] =>数组(
 [名称] => ALCOIN 
 [BasePlugin] => HTTP 
 [版本] => 1 
 [描述] => ALCO_IN操作的插件
  [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] =>数组(
 [xip:Action] =>数组(
  [@attributes] =>数组(
 [名称] => OfferActivationByOfferID 
 [版本] => 1.0 
 [ImagePath] => ./resources 
)
)
)
)
)  
  code>  pre> 
 
 

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

Assuming you are assigned to $yourVar like:

$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
            )
        )
    )
)

You would use:

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"];

It seems you might need this:

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