hi guys, how to get first and last (key and value) array multidimesional below?

    $data1 = array(
            array(
            '0'=>array(
            '7'=>'chelsea',
            '8'=>'everton',
            '9'=>'villa',
            '10'=>'liverpool'
            ),
            array(
            '23'=>'milan',
            '24'=>'inter',
            '25'=>'juventus',
                ),
                ),
            '1'=>array(
            array(
            '53'=>'madrid',
            '54'=>'barcelona',
            '55'=>'altetico',
            '56'=>'everton',        
            ),
            array(
            '243'=>'milan',
            '244'=>'inter',
            '245'=>'juventus',
                ),
            ),
            '2'=>array(
            array(
            '523'=>'madrid',
            '524'=>'barcelona',
            '525'=>'altetico',
            '526'=>'everton',
            ),
            array(
            '223'=>'milan',
            '224'=>'inter',
            '225'=>'juventus',
                ),
            )
            );

    i want yield like this:

    Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [7] => chelsea
                        [10] => liverpool
                    )

                [1] => Array
                    (
                        [23] => milan
                        [25] => juventus
                    )

            )

        [1] => Array
            (
                [0] => Array
                    (
                        [53] => madrid 
                        [56] => everton
                    )

                [1] => Array
                    (
                        [243] => milan
                        [245] => juventus
                    )

            )

        [2] => Array
            (
                [0] => Array
                    (
                        [523] => madrid
                        [526] => everton 
                    )

                [1] => Array
                    (
                        [223] => milan
                        [225] => juventus
                    )

            )

    )
Member Avatar for LastMitch

get first and last (key and value) array multidimesional

Can you provide the array code so we can understand you better.

Member Avatar for diafol

Sorry to post a putative solution, but the contrivance made an explanation difficult without it:

foreach($data1 as $ktop=>$dtop){
    foreach($dtop as $v){
        $value2 = end($v);
        $key2 = key($v);
        $value1 = reset($v);
        $key1 = key($v);
        $newarray[$ktop][] = array($key1=>$value1,$key2=>$value2);  
    }
}
echo "<pre>";
print_r($newarray);
echo "</pre>";

loop over each item in the outer array and have a nested loop looping - creating and then adding an item to the new array on every iteration
reset moves the pointer of the array to the beginning
end moves the pointer to the last item of the array

commented: Crystal ball works! +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.