作者LPH66 ((short)(-15074))
看板PHP
标题Re: [请益] 阵列的问题
时间Mon Dec 1 15:38:36 2008
※ 引述《bellboy (铃铛人)》之铭言:
: 请问大家
: 假设我有一个二维阵列如下:
: Array
: (
: [0] => Array
: (
: [id] => 1
: [status] => 'aaa'
: )
: [1] => Array
: (
: [id] => 2
: [status] => 'bbb'
: )
: [2] => Array
: (
: [id] => 3
: [status] => 'ccc'
: )
: )
: 我想要把这个阵列变成:
: Array
: (
: [0] => 'aaa'
: [1] => 'bbb'
: [2] => 'ccc'
: )
: 除了丢进回圈一个一个转之外,是不是有比较快的方法呢?
: 感谢!
其实丢回圈也没那麽繁啊:
foreach ($array as &$value)
{
$value=$value['status'];
}
unset($value);
最後一行的用意是因为foreach完之後 $value 会参考到阵列的最後一个元素
即使跳出回圈了一样还在 所以建议是用unset把它处理掉
避免之後用 $value 时出现意外状况
--
'Oh, Harry, dont't you
see?' Hermione breathed. 'If she could have done
one thing to make
absolutely sure that every single person in this school
will read your interview, it was
banning it!'
---'Harry Potter and the order of the phoenix', P513
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.30.84
1F:推 bellboy :感谢! 12/01 16:28