Array Problem help me?
This my array.... Array is dynamically created?
Array
(
[a1]=>'k'
[a2]=>'a'
[a3]=>'w'
[a4]=>'z'
}
i want
开发者_如何学JAVAArray
(
[a1]=>'k,a'
[a3]=>'w'
[a4]=>'z'
}
merging a1,a2 keys
Not sure if this was homework? Here's one solution:
<?php
$array['a1'] = $array['a1'] . ',' . $array['a2'];
unset($array['a2']);
$YOUR_ARRAY['a1']=$YOUR_ARRAY['a1'].','.$YOUR_ARRAY['a2'];
unset($YOUR_ARRAY['a2'])
In general, you can create nested arrays like so:
$a = array(array('a, b'), 'c', 'd');
And you can modify that sample accordingly.
Is your array is dynamically created or do you want only static or on what logic u want to second array based on first array,
otherwise if u give values like below then it will store values
Array
(
[a1]=>'k,a'
[a3]=>'w'
[a4]=>'z'
)
OR
Array
(
[a1]=>[a1].','.[a2]
[a3]=>'w'
[a4]=>'z'
)
unset([a2])
精彩评论