php - get next index of particular key value -
i've array this
[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 ) ) ) ) now first i've searched signer keyword code
if(stripos($eachitem['description'], "signer") !== false){} and i'm searching values in description keys.
foreach($items $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]; } } } now want description key of each index example @ index 1 description signer , @ index 2 description - sign , @ index 3 description 1 want description value of each index when concatenate description key value signer-1 in code next key boundingpoly of same index want description keys of each index.
you can this. output this: array('singer-1', 'singer-2', ...)
$visited = -1; $output = []; foreach($items $index => $item) { if($item['description'] == 'singer') { $output[$visited+1] = 'singer'; $visited++; } else { $output[$visited] .= $item['description']; } }
Comments
Post a Comment