I have an array: $ aPerfparse as a 2-dimensional array, where the index is in the range from 0 to n-1,
* aPerfparse[index]['label'] - label of the perfdata
* ['value'] - actual perfdata
* ['uom'] - unit of measurement (might be NULL)
Iterate through each element and set the value of each index and label to the segment. index based variable.
Without a loop, this would be:
$value0 = $aPerfdata[0]['value'];
$value1 = $aPerfdata[1]['value'];
What is right / wrong in this:
foreach ( $aPerfdata as $key => $value ) {
$value$key = $aPerfdata[$key]['value'];
$label$key = $aPerfdata[$key]['label'];
}
Similarly, I need to take these saved variables $ value and $ label and refer to them later in the foreach loop.
Without a loop, it would look like this:
ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+2, $oShadow, $fontFile, $label0 . ":" . " " . $value0);
ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+40, $oShadow, $fontFile, $label1 . ":" . " " . $value1);
What is right / wrong in this:
foreach ( $aPerfdata as $key => $value ) {
ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+$sz, $oShadow, $fontFile, $label$key . ":" . " " . $value$key);
sz=$sz+40;
}
Thank!
====
After each help, I have the following:
foreach ( $aPerfdata as $key => $value )
{
${'label'.$key} = $aPerfdata[$key]['label'];
${'value'.$key} = $aPerfdata[$key]['value'];
}
foreach ( $aPerfdata as $key => $value )
{
ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+$sz, $oShadow, $fontFile, ${'label'.$key} . ":" . " " . ${'value'.$key});
$sz=$sz+40;
}
I no longer need to smooth the array. I tried the method mentioned by Mark, but the ImageTTFText function is not executed.