开发者

Array Problem help me?

开发者 https://www.devze.com 2023-02-10 06:59 出处:网络
This my array.... Array is dynamically created? Array ( [a1]=>\'k\' [a2]=>\'a\' [a3]=>\'w\' [a4]=>\'z\'

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])
0

精彩评论

暂无评论...
验证码 换一张
取 消