I would like to compare two arrays of objects in PHP. But in most efficient way. I would like if value of object in array1 exist in any of object in array2. If so i would like to get it's ID's.
Array that I'm taking values to comprassion looks like that:
array(2) {
[0] =>
class stdClass#529 (4) {
public $value =>
string(4) "Name"
public $valueType =>
string(4) "text"
public $propertyName =>
string(13) "beeforwhiskey"
public $propertyType =>
NULL
}
[1] =>
class stdClass#530 (4) {
public $value =>
string(5) "Email"
public $valueType =>
string(4) "text"
public $propertyName =>
string(5) "email"
public $propertyType =>
string(4) "text"
}
}
The array that I would like to get ID's from looks like this:
array(37) {
[0] =>
class stdClass#532 (9) {
public $customFieldId =>
string(5) "xyz"
public $href =>
string(50) "..."
public $name =>
string(7) "address"
public $fieldType =>
string(4) "text"
public $format =>
string(4) "text"
public $valueType =>
string(6) "string"
public $type =>
string(4) "text"
public $hidden =>
string(5) "false"
public $values =>
array(0) {
}
}
[1] =>
class stdClass#538 (9) {
public $customFieldId =>
string(5) "zyx"
public $href =>
string(50) "..."
public $name =>
string(3) "age"
public $fieldType =>
string(13) "single_select"
public $format =>
string(13) "single_select"
public $valueType =>
string(6) "string"
public $type =>
string(13) "single_select"
public $hidden =>
string(5) "false"
public $values =>
array(5) {
[0] =>
string(5) "18-29"
[1] =>
string(5) "30-44"
[2] =>
string(5) "45-59"
[3] =>
string(3) "60+"
[4] =>
string(3) "<18"
}
}
.
.
.
So in this case I'm taking each object from array1, check the propertyName and if it exists in any of object in array2 in name field, then I would like to take it's id from array2.
I did this with some foreach'es but I know it's not the best way to do this. How can I make it shorter, more clear and less memory taking?