Home  >  Article  >  Backend Development  >  PHP 待方法

PHP 待方法

WBOY
WBOYOriginal
2016-06-13 13:04:13708browse

PHP 在线等待求一个方法.
我有一个数组

Array
(
    [P1211007] => 2
    [P1211008] => 3
 )
目前有2行数据,可能多少行未定.

我要把这个数据标准化成这样的数据
Array
(
    [1] => Array
        (
            [P1211007] => Array
                (
                    [pcode] => P1211007
                    [book_num] => 2                    
                )

            [P1211008] => Array
                (
                    [pcode] => P1211008
                    [book_num] => 3                    
                )
        )
)

本人PHP是菜鸟,各位朋友帮忙.
------最佳解决方案--------------------

$ar=Array<br />
(<br />
    'P1211007' => 2,<br />
    'P1211008' => 3<br />
 );<br />
 $arr=$new_arr=array();<br />
 foreach($ar as  $k=>$v){<br />
       $arr[$k]=array('pcode' =>$k,'book_num' => $v);<br />
 }<br />
 $new_arr[1]=$arr;<br />
 print_r($new_arr);

------其他解决方案--------------------
怎么没有人啊。。
------其他解决方案--------------------
谢谢一起混同学,

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