Convert PHP array into Key => Value Array
Posted
by
Feature
on Stack Overflow
See other posts from Stack Overflow
or by Feature
Published on 2011-03-04T15:19:15Z
Indexed on
2011/03/04
15:24 UTC
Read the original article
Hit count: 180
Total PHP Noob and I couldn't find an answer to this specific problem. Hope someone can help!
$myvar is an array that looks like this:
Array (
[aid] => Array (
[0] => 2
[1] => 1
)
[oid] => Array(
[0] => 2
[1] => 1
)
)
And I need to set a new variable (called $attributes) to something that looks like this:
$attributes = array($myvar['aid'][0] => $myvar['oid'][0], $myvar['aid'][1] => $myvar['oid'][1], etc...);
And, of course, $myvar may contain many more items...
How do I iterate through $myvar and build the $attributes variable?
© Stack Overflow or respective owner