-1

let me say I have an array like this:

$testarray = array('abc'=>'123',
              'def'=>'456',
              'ghi'=>'789'
);

For an operation I need the single values of the array in variables. I would like to loop through the array and have something like this:

new cmdOption("cn", $arrayvaluefirstcolumn, "User")

new cmdOption("mod", "text=".$arraysecondcolumn, "expression")

So, I would like to have 'abc' as $arrayvaluefirstcolumn and '123' as $arrayvaluesecondcolumn in the first loop. And in the second loop, I would like to have 'def' as $arrayvaluefirstcolum and '456' as $arrayvaluesecondcolumn and so on.

I am not sure how to loop through the array to get the desired result and store it in the variables. Is this possible? Can you give me some advice?

1

2 Answers 2

1

The only thing you need to do is to loop through your array.

$testarray = array(
    'abc' => '123',
    'def' => '456',
    'ghi'=>'789'
);

foreach ($testArray as $key => $value) {
    new cmdOption("cn", $key, "User");
    new cmdOption("mod", "text=".$value, "expression");
}
Sign up to request clarification or add additional context in comments.

Comments

0
foreach($testarray as $key => $value)
{
    //returns 'abc', 'def', 'ghi'
    $arrayvaluefirstcolumn = $key;
    //returns '123', '456', '789'
    $arrayvaluesecondcolumn = $value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.