0

my head is starting to explode :(

I am trying to put index of array as a name of input and value of array as value of input. I simply need it to do this way :)

array named $arrAddItems which I go through is:

array(2) {
  [0]=>
  array(1) {
    [479]=>
    string(2) "83"
  }
  [1]=>
  array(1) {
    [345]=>
    string(3) "348"
  }
}

I need this output when form is submitted:

 [345]=>
  array(1) {
    [0]=>
    string(3) "348"
  }

 [479]=>
  array(1) {
    [0]=>
    string(3) "83"
  }

My code to do that is:

foreach($arrAddItems as $addItem) { echo key($addItem);?>
    <input type="hidden" name="<?=key($addItem);?>[]" value="<?=$addItem;?>">
<?php
}
?>

I know it is something obvious, but I cannot see it :(

Thx for help. martin

2 Answers 2

1

try to

foreach($arrAddItems as $key => $value){
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

0

I found solution - this is the right code:

foreach($arrAddItems as $addItem) { ?>
    <input type="hidden" name="<?=key($addItem);?>[]" value="<?=$addItem[key($addItem)];?>">
<?php
}
?>

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.