The key, by definition, must be unique. What you can do is, make an array called $persons
, with the following data:
Array (
[1] => Array (
[name] => Bob
[age] => 23
)
[2] => Array (
[name] => Tom
[age] => 33
)
...
)
You can do this as follows:
$persons = Array();
for($i = 0; $i < sizeof($arr["name"]); $i++) {
$persons[$i]["name"] = $arr["name"][$i];
$persons[$i]["age"] = $arr["age"][$i];
}
Sample output:
Array
(
[0] => Array
(
[name] => Bob
[age] => 23
)
[1] => Array
(
[name] => Tom
[age] => 33
)
[2] => Array
(
[name] => Ryan
[age] => 43
)
...
)