从关联数组的数组中删除选定的元素 [英] Removing selected elements from array of associative arrays
本文介绍了从关联数组的数组中删除选定的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有关联数组的数组如下
I have the following array of associative arrays.
$result = array(
(int) 0 => array(
'name' => 'Luke',
'id_number' => '1111',
'address' => '1544addr',
'time_here' => '2014-04-12 13:07:08'
),
(int) 1 => array(
'name' => 'Sam',
'id_number' => '2222',
'address' => '1584addr',
'time_here' => '2014-04-12 14:15:26'
我想从这个数组,这样它看起来就像这样删除选定的元素;
I want to remove selected elements from this array such that it will look like this;
array(
(int) 0 => array(
'name' => 'Luke',
'id_number' => '1111'
),
(int) 1 => array(
'name' => 'Sam',
'id_number' => '2222',
这是code我写的;
This is the code I wrote;
foreach($result as $value)
{
unset($value('address') );
unset($value('time_here') );
}
当我运行code,Apache Web服务器崩溃。
When I run the code, Apache web server crashed.
能否聪明成员指出,我做了什么错?非常感谢你。
Can the smarter members point out what did I do wrong? Thank you very much.
推荐答案
数组表示法是错误的,用这个;
Array notation is wrong, use this;
$finalResult = array();
foreach($result as $value)
{
unset($value['address'] );
unset($value['time_here'] );
$finalResult[] = $value;
}
下面是一个工作演示: 演示
Here is a working demo: Demo
这篇关于从关联数组的数组中删除选定的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文