Hello All,
let me first warn you guys that I am a bit of a newbie so don't be scared by my awful code.
I have two arrays, the first array is a multidimensional array which you can see below
Array (
[0] => Array (
[guardian_id] => 00001
[guardian_firstname] => Eluvia
[guardian_lastname] => Perez
[guardian_mobile] => data1 [guardian_workname] => data2
[guardian_workph] => data7 [guardian_workphext] => data8
)
[1] => Array (
[guardian_id] => 00002
[guardian_firstname] => Pancho
[guardian_lastname] => Sanchez
[guardian_mobile] => [guardian_workname] =>
[guardian_workph] => [guardian_workphext] =>
)
[2] => Array (
[guardian_id] => 00003
[guardian_firstname] => Elvia [guardian_lastname] => Ayala
[guardian_mobile] => [guardian_workname] =>
[guardian_workph] => [guardian_workphext] =>
)
[3] => Array (
[guardian_id] => 00004
[guardian_firstname] => Nazario C.
[guardian_lastname] => Ayala
[guardian_mobile] =>
[guardian_workname] =>
[guardian_workph] =>
[guardian_workphext] =>
)
[4] => Array (
[guardian_id] => 00005
[guardian_firstname] => Yvonne
[guardian_lastname] => Le Blanc [guardian_mobile] =>
[guardian_workname] =>
[guardian_workph] =>
[guardian_workphext] =>
)
)
and the second array is below.
Array (
[00002] => checked
[00003] => checked
[00005] => checked
)
I would like to use the keys from the second array "00002","00003","00005" and use them to remove the sub-arrays whose key "[guardian_id]" equal the above numbers. I wrote something that almost did want using the unset function but it does not remove the elements, it just empties them. The code I am using is the following.
$this->data is the first array
$omited is the second array
if(is_array($omited)){
foreach($omited as $key => $value){
//prefrom check against key
for($i=0, $size = count($this->data); $i<$size; $i++){
if($this->data[$i][$needle] == $key){
unset($this->data[$i]);
}
}
}
$this->numrows = count($this->data);
return true;
}else{
return false;
}
The question is why dose this not work.