如何从Array中解析值?这是我的示例数组代码?

时间:2017-12-06 05:14:00

标签: php arrays parsing

Array
(
    [Action] => Array
        (
            [0] => Array
                (
                    [@attributes] => Array
                        (
                            [Name] => OfferActivationByOfferID
                            [Version] => 1.0
                            [ImagePath] => ./resources
                        )
                )
            [1] => Array
                (
                    [@attributes] => Array
                        (
                            [Name] => Ranjith
                            [Version] => 1.0
                            [ImagePath] => ./resources
                        )
                )
        )
)

在这个数组中我需要[Name]属性Value for Every Action tag.please do help。

示例输出;

1.OfferActivationByOfferID

2.Ranjith

2 个答案:

答案 0 :(得分:0)

希望您将数组数据保存在某个变量中。这很简单: -

$data = //Your arraydata
foreach($data['Action'] as $key=> $value){
    echo $value['@attributes']['Name'];
}

希望它有所帮助!

答案 1 :(得分:0)

$data = //Your full array
$names = array();
// then loop through the array
foreach($data['Action'] as $key=> $value){
    $names[] = $value['@attributes']['Name'];
}

所以$names将拥有原始数组的所有名称。