search

Home  >  Q&A  >  body text

How to convert multi-dimensional array into one-dimensional array in thinkphp?

Array
(

[0] => Array
    (
        [user_id] => 1
    )

[1] => Array
    (
        [user_id] => 22
    )

)
I only want 1 and 22. How to change it into $a=array('1','22');

天蓬老师天蓬老师2783 days ago423

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-05-16 13:15:51

    php版本要大于5.5.0
    $userid_array = array_column($x,'userid');
    
    
    php版本要大于5.4.0
    $userid_array = array_map(function($item){return $item['userid'];},$x);
    
    再低就for循环吧

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:15:51

    array_map("current", two-dimensional array);

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:15:51

    Do you need to query by column? Such a query can directly find the data of a one-digit array

    $use_id = Db->table('table')->where([])->column('user_id');

    reply
    0
  • Cancelreply