Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

thinkphp怎么将多维数组变成一维数组?

Array
(

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

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

)
我只想要 1和22 怎么变成$a=array('1','22');


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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循环吧

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...