Andreas
Andreas

Reputation: 193

Sort array based on key value

I'm using a form where the pair of inputs can be added per automatic. One store value in select and the other as input

After submit I receive the values in array and I need to associate them together. So all key values [0] belongs together and all [1] and so on.

Array
(
[issue] => Array
    (
        [0] => 2
        [1] => 3
    )

[qty] => Array
    (
        [0] => 1
        [1] => 2
    )
)

How can I do this using PHP?

Upvotes: 0

Views: 36

Answers (1)

miken32
miken32

Reputation: 42760

Just use a simple foreach loop.

$combined = array();
foreach ($_POST["issue"] as $k=>$v) {
  $combined[$k] = array($_POST["issue"][$k], $_POST["qty"][$k]);
}
print_r($combined);

Upvotes: 1

Related Questions