我是这样的阵列
[1] => Array(
[description] => signer
[boundingPoly] => Array (
[vertices] => Array (
[0] => Array
(
[x] => 399
[y] => 408
)
[1] => Array
(
[x] => 557
[y] => 408
)
[2] => Array
(
[x] => 557
[y] => 457
)
[3] => Array
(
[x] => 399
[y] => 457
)
)
)
)
[2] => Array (
[description] => -
[boundingPoly] => Array (
[vertices] => Array (
[0] => Array
(
[x] => 399
[y] => 408
)
[1] => Array
(
[x] => 557
[y] => 408
)
[2] => Array
(
[x] => 557
[y] => 457
)
[3] => Array
(
[x] => 399
[y] => 457
)
)
)
)
[3] => Array (
[description] => 1
[boundingPoly] => Array (
[vertices] => Array (
[0] => Array
(
[x] => 399
[y] => 408
)
[1] => Array
(
[x] => 557
[y] => 408
)
[2] => Array
(
[x] => 557
[y] => 457
)
[3] => Array
(
[x] => 399
[y] => 457
)
)
)
)
现在我首先使用此代码
搜索了signer
个关键字
if(stripos($eachItem['description'], "signer") !== false){}
然后我搜索description
键中的值。
foreach($items as $index => $eachItem) {
if(stripos($eachItem['description'], "signer") !== false) {
if($eachItem['description'] == "signer") {
$current = $eachItem['description'];
$keys = array_keys($eachItem);
$ordinal = (array_search($current,$keys)+1)%count($keys);
$next = $keys[$ordinal];
}
}
}
现在我想要的是获取每个索引的description
键,例如在索引1 description
是signer
而索引2 description
是{{1} }并且在索引3 -
处description
现在我想要1
每个索引的值,所以当我连接description
键时,值将是这样的{{1}在我的代码中,它获得了相同索引的description
的下一个键,但我只想要每个索引的signer-1
个键。
答案 0 :(得分:0)
你可以简单地这样做。输出如下:array('singer-1', 'singer-2', ...)
$visited = -1;
$output = [];
foreach($items as $index => $item) {
if($item['description'] == 'singer')
{
$output[$visited+1] = 'singer';
$visited++;
}
else
{
$output[$visited] .= $item['description'];
}
}
答案 1 :(得分:0)
仍然不确定您的预期输出。但是,如果你只想要键
,请试试这个$a = [
["description" => "signer"],
["description" => "-"],
["description" => "1"]
];
//To get all values of description key
$desKeys = array_column($a, 'description'); //output ["singer", "-", "1"]
echo implode('', desKeys ); //output singer-1