I have an array of objects that I am iterating to find the records that have EmailType = INST, get their registration and eliminate the records that have that registration.
I share my code, I get the license plate, I only need to delete the records that have that license plate. I tried to do the removal with PHP's unset() function but it won't stick. I hope you can support me.
I would thank you a lot.
array
Array (
[0] => stdClass Object (
[matricula] => 000000096
[FIRST_NAME] => JOSE
[MIDDLE_NAME] => AGUSTIN
[a_paterno] => ARELLANO
[a_materno] => LOPEZ
[estatus] => NUIN
[EmailType] => PERS
[email_people] => [email protected] )
[1] => stdClass Object (
[matricula] => 000000269
[FIRST_NAME] => LUIS
[MIDDLE_NAME] => FERNANDO
[a_paterno] => BOCANEGRA
[a_materno] => RAMIREZ
[estatus] => NUIN
[EmailType] => INST
[email_people] => [email protected] )
[2] => stdClass Object (
[matricula] => 000000269
[FIRST_NAME] => LUIS
[MIDDLE_NAME] => FERNANDO
[a_paterno] => BOCANEGRA
[a_materno] => RAMIREZ
[estatus] => NUIN
[EmailType] => PERS
[email_people] => [email protected] )
[3] => stdClass Object (
[matricula] => 000000270
[FIRST_NAME] => SERGIO
[MIDDLE_NAME] => ENRIQUE
[a_paterno] => BOCANEGRA
[a_materno] => RAMIREZ
[estatus] => NUIN
[EmailType] => INST
[email_people] => [email protected] )
[4] => stdClass Object (
[matricula] => 000000270
[FIRST_NAME] => SERGIO
[MIDDLE_NAME] => ENRIQUE
[a_paterno] => BOCANEGRA
[a_materno] => RAMIREZ
[estatus] => NUIN
[EmailType] => PERS
[email_people] => [email protected] )
[5] => stdClass Object (
[matricula] => 000000292
[FIRST_NAME] => ANDREA
[MIDDLE_NAME] =>
[a_paterno] => CASTAÑEDA
[a_materno] => BASURTO
[estatus] => NUIN
[EmailType] => INST
[email_people] => [email protected] )
[6] => stdClass Object (
[matricula] => 000000292
[FIRST_NAME] => ANDREA
[MIDDLE_NAME] =>
[a_paterno] => CASTAÑEDA
[a_materno] => BASURTO
[estatus] => NUIN
[EmailType] => LABOR
[email_people] => [email protected] )
[7] => stdClass Object (
[matricula] => 000000292
[FIRST_NAME] => ANDREA
[MIDDLE_NAME] =>
[a_paterno] => CASTAÑEDA
[a_materno] => BASURTO
[estatus] => NUIN
[EmailType] => PERS
[email_people] => [email protected] )
[8] => stdClass Object (
[matricula] => 000000340
[FIRST_NAME] => AXEL
[MIDDLE_NAME] =>
[a_paterno] => CAZARIN
[a_materno] => MINCHACA
[estatus] => NUIN
[EmailType] => INST
[email_people] => [email protected] ) )
Function
function getInstitucionalAlumnosSinAccesos()
{
if (!isset($this->session->userdata['sess_data']['id_usuario'])) {
redirect(base_url().'Auth');
}
try {
$tipo_operacion = 1;
$elements = $this->Institutional_alumnos_model->getInstitucionalAlumnosSinAccesos();
if ($tipo_operacion == 1) {
foreach ($elements as $key => $value) {
if ($value->EmailType == 'INST') {
$matricula = $value->matricula;
//Aquí debería de eliminar los registros que tenga la matricula guardada en la variable $matricula
}
}
}
} catch (Exception $e) {
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
} //./catch
}
I think the most appropriate thing would be to omit those records from the query, with a
emailType != 'INST'
. If this is not possible, or if you want to continue with your current code, here is a proposal:You first create an array to store the license plates that need to be removed, and then iterate through the elements again to remove the ones inside the array:
Just keep in mind that the indices are not going to be consecutive anymore, if you need to traverse the array again, it will have to be done again with
foreach($elements as $key => $value)
, or simply withforeach($elements as $value)
because you don't need the index anymore.