Problems with PHP array conversion

Source: Internet
Author: User
Array([server] => Array(        [0] => hk        [1] => jp    )[fromdate] => Array(        [0] => 2013-07-17        [1] => 2013-06-19))

The above array if the fastest and simplest method is converted into

Array([0] => Array(    [server] => 'hk',    [fromdate] => '2013-07-17')[1] => Array(    [server] => 'jp',    [fromdate] => '2013-07-17'))

Reply content:

Array([server] => Array(        [0] => hk        [1] => jp    )[fromdate] => Array(        [0] => 2013-07-17        [1] => 2013-06-19))

The above array if the fastest and simplest method is converted into

Array([0] => Array(    [server] => 'hk',    [fromdate] => '2013-07-17')[1] => Array(    [server] => 'jp',    [fromdate] => '2013-07-17'))

// 源数组$source = array(    'server' => array('hk','jp'),    'fromdate' => array('2013-07-17','2013-07-08'));//目标数组$result = array();foreach($source as $key=>$value){    $j = 0;    // 当然用这里用foreach也可以实现,但是for循环更能直观了解它的怎么工作的。    for($i=0;$i
  
   
   ';print_r($result);echo '
  
';

$source = array(    'server' => array('hk','jp'),    'fromdate' => array('2013-07-17','2013-07-08'));$new_array = array_map(function($server,$fromdate) {    return array('server'=>$server,'fromdate'=>$fromdate);}, $source['server'],$source['fromdate']); //代码比较少
  • 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.