Arrays 如何检查对象中是否存在属性?
这是我的对象Arrays 如何检查对象中是否存在属性?,arrays,symfony,oop,object,properties,Arrays,Symfony,Oop,Object,Properties,这是我的对象字段: {#7139 ▼ +"id": array:9 [▼ "fieldName" => "id" "type" => "integer" "scale" => 0 "length" => null "unique" => false "nullable" => false "precision" => 0 "id" => true "columnName"
字段
:
{#7139 ▼
+"id": array:9 [▼
"fieldName" => "id"
"type" => "integer"
"scale" => 0
"length" => null
"unique" => false
"nullable" => false
"precision" => 0
"id" => true
"columnName" => "id"
]
+"name": array:8 [▼
"fieldName" => "name"
"type" => "string"
"scale" => 0
"length" => 255
"unique" => false
"nullable" => false
"precision" => 0
"columnName" => "name"
]
+"unique_id": array:8 [▼
"fieldName" => "unique_id"
"type" => "string"
"scale" => 0
"length" => 10
"unique" => true
"nullable" => false
"precision" => 0
"columnName" => "unique_id"
]
+"productgroup": array:20 [▼
"fieldName" => "productgroup"
"joinTable" => array:3 [▶]
"targetEntity" => "App\Entity\Productgroup"
"mappedBy" => null
"inversedBy" => null
"cascade" => []
"orphanRemoval" => false
"fetch" => 2
"type" => 8
"isOwningSide" => true
"sourceEntity" => "App\Entity\Products"
"isCascadeRemove" => false
"isCascadePersist" => false
"isCascadeRefresh" => false
"isCascadeMerge" => false
"isCascadeDetach" => false
"joinTableColumns" => array:2 [▶]
"isOnDeleteCascade" => true
"relationToSourceKeyColumns" => array:1 [▶]
"relationToTargetKeyColumns" => array:1 [▶]
]
}
我想获取包含relationToSourceKeyColumns
这是我的方法:
foreach ($fields as $field) {
$ManyToMany = property_exists($field['fieldName'], 'relationToSourceKeyColumns');
if($ManyToMany == true){
$result = $field['fieldName'];
}
}
结果是:
""
"productgroup"
但我的预期结果是:
""
"productgroup"
函数
属性\u存在
用于对象()。在您的结构中,搜索键位于数组中,可以使用array\u key\u exists
() 函数属性_存在
用于对象()。在您的结构中,搜索键位于数组中,可以使用array\u key\u exists
() 啊,这是正确的解决方案:array\u key\u exists('relationToSourceKeyColumns',$field)
啊,这是正确的解决方案:array\u key\u exists('relationToSourceKeyColumns',$field)