简体   繁体   English

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

[英]How to get value of certificate name from the following array in php:

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

It is the response I am getting after using listServerCertificates function provided by aws api for php. 这是我使用aws api为php提供的listServerCertificates函数后得到的响应。

The output should be value of ServerCertificateName which is 'mycert'as a string I have tried using array_search function. 输出应该是ServerCertificateName的值,这是我使用array_search函数尝试过的字符串“ mycert”。

You can get like this, 你可以这样

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

or 要么

$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'];
            }
        }
    }

This should work. 这应该工作。

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

I have tested it like this. 我已经测试过了

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM