简体   繁体   中英

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.

The output should be value of ServerCertificateName which is 'mycert'as a string I have tried using array_search function.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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