如何从php中的以下数组中获取证书名称的值:

时间:2014-02-08 07:12:11

标签: php arrays

Array (
   [IsTruncated] =>
   [ServerCertificateMetadataList] => Array (
   [0] => Array (
      [ServerCertificateName] => mycert
      [Path] => /
      [Arn] => arn:aws:iam::100000693058:server-certificate/mycert
      [UploadDate] => 2014-02-01T08:30:29Z
      [ServerCertificateId] => ASCAJYHRTGHHJ4QTT5RFVBM
   )
)
   [ResponseMetadata] => Array (
      [RequestId] => b2226082-908e- 11e3-a293-9d669aac8ae3
   )
) 

这是我使用aws api为php提供的listServerCertificates函数后得到的响应。

输出应为ServerCertificateName的值,即'mycert'为字符串 我尝试过使用array_search函数。

2 个答案:

答案 0 :(得分:1)

你可以这样,

echo $yourVariableName['ServerCertificateMetadataList'][0]['ServerCertificateName'];

$array = array('Istruncated' => '', 'ServerCertificateMetadataList' => array(array('ServerCertificateName' => 'mycert', 'Path' => '/')));
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            foreach ($value as $value1) {
                echo $value1['ServerCertificateName'];
            }
        }
    }

答案 1 :(得分:0)

这应该有用。

echo $arr[ServerCertificateMetadataList][0][ServerCertificateName];

我已经测试过了。

$arr = Array (
    "IsTruncated" => "",
    "ServerCertificateMetadataList" => Array (
        0 => Array (
        "ServerCertificateName" => "mycert",
        "Path" => "/",
        "Arn" => "arn:aws:iam::100000693058:server-certificate/mycert",
        "UploadDate" => "2014-02-01T08:30:29Z",
        "ServerCertificateId" => "ASCAJYHRTGHHJ4QTT5RFVBM"
        )
    ),
    "ResponseMetadata" => Array (
        "RequestId" => "b2226082-908e- 11e3-a293-9d669aac8ae3"
    )
);

echo $arr[ServerCertificateMetadataList][0][ServerCertificateName];