Reputation: 1
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?
Upvotes: 0
Views: 383
Reputation: 795
Look at this example taken from the documentation (http://php.net/manual/en/function.array-map.php):
<?php
function cube($n)
{
return($n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);
It will return an array with 1, 8, 27, etc ...
The name $items
you used for the parameter is misleading, because the argument will be each single $item
of your array, and array_map()
is supposed to transform it somehow.
I'm not sure about what you want to do, but apparently you won't need array_map()
for your purpose.
Upvotes: 1