Try use function array_map
array_map(function ($items) {
return $items[$this->relatedKey];
}, $this->parseIds($ids))
$ids is array of item => value:
$ids = array:1 [
"parent_id" => "15"
]
Key what need to find:
$this->relatedKey = "parent_id"
And get error:
Illegal string offset 'parent_id'
What I do wrong?
array_mapon an array, you get the values in the var$items, so"15"in your case, and"15"has no index "parent_id", it's not an array. It seems you usearray_mapfor the wrong purpose, it is used to apply a function to all items in an array and return resulting new array with affected values. To acces a specific key in PHP, simply use$ids[$this->relatedKey]