L
L
Lavrov952018-03-03 13:49:40
PHP
Lavrov95, 2018-03-03 13:49:40

How to make it look like this array using foreach?

$array = [
                [
                    'column 1',
                    'column 2',
                ],
                [
                    1,2
                ]
            ];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2018-03-03
@coderisimo

80% of success is a normally formulated question))). Moreover, often when you formulate , you find the answer yourself)))
I will assume that from one array you need to get another, where the first subarray contains the keys, and the second contains the values. For example :

$testArray = ['1'=>'ОДЫН', '2'=>'ДЫВА' , '3'=>'ТРЫ',  '4'=>'ЧЯТЫРЯ' ];
$result =[];
foreach($testArray as $k=>$v){
    $result[0][] =  $k;
    $result[1][] =  $v;
 }

var_dump($result);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question