Home  >  Article  >  Backend Development  >  How to add array elements in two dimensions in php

How to add array elements in two dimensions in php

藏色散人
藏色散人Original
2021-05-17 10:21:164395browse

php method to add array elements in two dimensions: first create a two-dimensional array "$consult"; then append the elements of "$arr" to the front of "$consult".

How to add array elements in two dimensions in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php appends elements to a two-dimensional array, php two Method of adding array elements to the dimension

Previous data processing:

After processing:

   //$consult 为往里插之前的数组
        //把$arr的元素追加到$consult的最前面
        $arr = [];
        $arr[0]['workplaceId'] = '0';
        $arr[0]['workplaceName'] = '信息部';
        $arr[0]['List'] = [['typeId' => 3, 'typeName' => '全部']];
        array_walk($arr,function($item) use (&$consult) {
            array_unshift($consult, $item);
        });

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to add array elements in two dimensions in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn