Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:01:20+00:00 2026-05-16T21:01:20+00:00

I have an array: $aPerfparse as 2-dimensional array where index ranges from 0 to

  • 0

I have an array:
$aPerfparse as 2-dimensional array where index ranges from 0 to n-1,

* aPerfparse[index]['label']         -   label of the perfdata  
*                  ['value']         -   actual perfdata  
*                  ['uom']           -   unit of measurement (might be NULL)

Need to iterate through each item and set each indexes ‘value’ and ‘label’ to a sep. variable based-on the index.

Without a loop, it would be:

$value0 = $aPerfdata[0]['value'];  
$value1 = $aPerfdata[1]['value'];

What is correct/incorrect about this?:

foreach ( $aPerfdata as $key => $value ) {  
    $value$key = $aPerfdata[$key]['value'];  
    $label$key = $aPerfdata[$key]['label'];   
}

Similarly, I need to take those stored $value and $label variables and reference them later in a foreach loop.

Without a loop, it would look like:

ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+2, $oShadow, $fontFile, $label0 . ":" . " " . $value0);  
ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+40, $oShadow, $fontFile, $label1 . ":" . " " . $value1);

What is correct/incorrect about this?:

foreach ( $aPerfdata as $key => $value ) {  
    ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+$sz, $oShadow, $fontFile, $label$key . ":" . " " . $value$key);  
    sz=$sz+40;  
} 

Thank you!

====

After everyone’s help, I have the following working:

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 don’t really have a need to flatten the array anymore. I tried the method mentioned by Mark, but the ImageTTFText function doesn’t execute.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:01:20+00:00Added an answer on May 16, 2026 at 9:01 pm

    Why not just do

    foreach ( $aPerfdata as $value ) {  
        ImageTTFText($img, $fontSize, $fontRotation, 2, $fontSize+$sz, $oShadow, $fontFile, $value['label'] . ":" . " " . $value['value']);  
        $sz=$sz+40;  
    } 
    

    Among other things I think your use of variable variables is incorrect. You should really have something like:

    ${'value'.$key}
    

    But really you should just be using an array rather than variable variables – and since you already have an array there’s no real need to flatten it (as I show you above).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array of strings, String[] data and it's 10 elements has value P
I have array data as shown below, I want to store 'sale' value into
I have array number = {2,3,4,5,6} Now i have to select rows from table
I have a two dimensional array that I need to load data into. I
i have an array structured like: $something = array( 0 => array( 'label' =>
Imagine I have array of values ranging from 1 to 24. I want to
I have array with int values int[] myArr = (int[]) alItems.ToArray(typeof (int)); index =
I have array values of up[]={0,0,0,0,0} and view=adult thesetwo value i want to store
I have a PHP Array, and I want to extract from it the duplicated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.