php - Remove all numeric index to have an assoc array only
184
If i have an array like this after issuing a print_r() statement:
//print_r($theArray)
array (size=5)
0 =>
array (size=1)
'Animal' => string 'Dog' (length=3)
1 =>
array (size=1)
'House' => string 'white house' (length=11)
2 =>
array (size=1)
'Human' =>
array (size=3)
'Africans' => string 'Nigroids' (length=8)
'Europeans' => string 'Caucasoids' (length=8)
'Asians' => string 'Mugoloids' (length=8)
how can i remove all numeric indices such that above array becomes
array(
'Animal' => string 'Dog' (length=3),
'House' => string 'white house' (length=11),
'Human' =>
array (size=3)
'Africans' => string 'Nigroids' (length=8),
'Europeans' => string 'Caucasoids' (length=8),
'Asians' => string 'Mugoloids' (length=8)
)
any help is please ?
Answer
Solution:
One foreach just enough
Answer
Solution:
As simple as:
This is equivalent to the following, just with an arbitrary number of arrays:
Alternatively, for some functional fun:
Which is equivalent to:
Answer
Solution:
Double
foreach()
would work:Gives you: