Im trying to find a value inside a object, but I cant seem to get what isset is doing. Maybe Im using it wrong. I have two objects and what Im trying to do is delete the row which is not in the second object. Here is the object 1:
Array (
[idCategory1] => 1
[idCategory2] => 2
[idCategory4] => 4
)
And here is object 2:
Array (
[0] => Array (
[CategoriesProvider] => Array (
[id] => 28
[provider_id] => 2
[category_id] => 1
[created] => 2015-03-13 20:25:17
[modified] => 2015-03-13 20:25:17
)
)
[1] => Array (
[CategoriesProvider] => Array (
[id] => 29
[provider_id] => 2
[category_id] => 2
[created] => 2015-03-13 20:25:17
[modified] => 2015-03-13 20:25:17
)
)
[2] => Array (
[CategoriesProvider] => Array (
[id] => 30
[provider_id] => 2
[category_id] => 4
[created] => 2015-03-13 20:25:17
[modified] => 2015-03-13 20:25:17
)
)
)
Here is my code to delete the row of object 2 which is not in object 1.
foreach ($CategoriesOfProvider as $key ) {
if(isset($CategoriesProvider['CategoriesProvider']->$key['CategoriesProvider']['category_id'])) {
} else {
$this->User->Provider->CategoriesProvider->id = $key['CategoriesProvider']['id'];
//$this->request->allowMethod('post', 'delete');
if ($this->User->Provider->CategoriesProvider->delete()) {
} else {
$this->Session->setFlash(
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> No se pudo borrar la relacion producto - categoría.',
'default',
array('class' => 'alert alert-danger alert-dismissible', 'type' => 'alert')
);
}
}
}
$CategoriesOfProvider
is object 2 and $CategoriesProvider
is object 1. So Im trying to use isset to find if the id in object 2 is in the value of the object 1. I think Im using isset wrong. Or is there another way? I thought of maybe run it against each of the values of object 1. Would that work better?
Thanks in advance for your help.