I have an array created from loop which is returning the correct data
$ku = array();
$oid = array('id-ce-keyUsage');
if(isset($chain['tbsCertificate']['extensions'])) {
$count = count($chain['tbsCertificate']['extensions']);
for($i = 0; $i < $count; $i++) {
$count2 = count($chain['tbsCertificate']['extensions'][$i]['extnValue']);
for($j = 0; $j < $count2; $j++) {
if(array_key_exists('extnId', $chain['tbsCertificate']['extensions'][$i]) &&
in_array($chain['tbsCertificate']['extensions'][$i]['extnId'], $oid)) {
$value = $chain['tbsCertificate']['extensions'][$i]['extnValue'][$j];
$ku[] = $value;
}
}
}
}
print_r($ku);
The above code produces this, which is correct.
Array
(
[0] => keyEncipherment
[1] => digitalSignature
)
Array
(
[0] => cRLSign
[1] => keyCertSign
)
Array
(
[0] => cRLSign
[1] => keyCertSign
)
However, I would like to be able to print the values of $ku on their own, like so:
keyEncipherment, digitalSignature
cRLSign, keyCertSign
cRLSign, keyCertSign
I tried the following code but the results, and although the results look accurate, its actually adding the results of each iteration together rather then keeping them separate.
Here is the code im trying:
foreach ($ku as $val) {
$temp[] = "$val";
$key_usage = implode(', ', $temp);
}
echo $key_usage;
and here is the result:
keyEncipherment, digitalSignature
keyEncipherment, digitalSignature, cRLSign, keyCertSign
keyEncipherment, digitalSignature, cRLSign, keyCertSign, cRLSign, keyCertSign
Would appreciate some assistance. Happy to share more code if needed.
-UPDATE-
This code seems to help but hoping to find a better solution where i can just echo a string without []
$len=count($ku);
for ($i=0;$i<$len;$i++)
echo $ku[$i].', ';