PHP waiting method

Source: Internet
Author: User
PHP waits for a method online. I have an Array (& nbsp; [P1211007] & nbsp ;=& gt; & nbsp; 2 & nbsp; & nbsp; [P1211008] & nbsp; = & gt; & nbsp; 3 & nbsp;) currently there are 2 PHP online waiting methods.
I have an array

Array
(
[P1211007] => 2
[P1211008] => 3
)
There are currently two rows of data, and the number of rows may not be determined.

I want to standardize this data into such data
Array
(
[1] => Array
(
[P1211007] => Array
(
[Pcode] => P1211007
[Book_num] => 2
)

[P1211008] => Array
(
[Pcode] => P1211008
[Book_num] => 3
)
)
)

I am a newbie in PHP. you can help me.
------ Best solution --------------------
$ar=Array
(
    'P1211007' => 2,
    'P1211008' => 3
 );
 $arr=$new_arr=array();
 foreach($ar as  $k=>$v){
       $arr[$k]=array('pcode' =>$k,'book_num' => $v);
 }
 $new_arr[1]=$arr;
 print_r($new_arr);

------ Other solutions --------------------
No one else ..
------ Other solutions --------------------
Thank you,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.