search

Home  >  Q&A  >  body text

php 二维数组

  0 => 
    array =>
      'orderno' => '150228085016' 
      'delivery_time' => '1425124096' 
      'create_time' => '1425174370'
  1 => 
    array =>
      'orderno' => '150228084786' 
      'delivery_time' => '1425124096'
      'create_time' => '1425174374' 
  2 => 
    array =>
      'orderno' => '150228090539'
      'delivery_time' => '1425123584'
      'create_time' => '1425174387'

数组如上,我想使用对每组数组中的delivery_time 和 create_time键使用Date函数,得出结果如下:

  0 => 
    array =>
      'orderno' => '150228085016' 
      'delivery_time' => '2015-03-11' 
      'create_time' => '2015-03-11'
  1 => 
    array =>
      'orderno' => '150228084786' 
      'delivery_time' => '2015-03-11'
      'create_time' => '2015-03-11' 
  2 => 
    array =>
      'orderno' => '150228090539'
      'delivery_time' => '2015-03-11'
      'create_time' => '2015-03-11'

除了循环之外,PHP数组有没有内置的方法?

天蓬老师天蓬老师2851 days ago329

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-10 15:27:36

        $arr = array_map(function ($n) {
            return date('Y-m-d', $n);
        }, array_column($arr, 'create_time'));
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-10 15:27:36

    array_map

    reply
    0
  • ringa_lee

    ringa_lee2017-04-10 15:27:36

    假设你上面那个数组叫 $a...

    function mydate($t)
    {
        return date("Y/m/d",$t);
    }
    $ct = array_map("mydate",array_column($a,'create_time'));
    print_r($ct);
    

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-10 15:27:36

    array_column是5.5才支持的函数;需要向下兼容。

    使用array_walk_recursive处理,会完美解决你的问题~~

    reply
    0
  • Cancelreply