<?php
$objs = [ ['value'=>2, 'key'=>'a'], ['value'=>3, 'key'=>'b'] ];
$keys = array_column($objs, 'key');
$index = array_search('c', $keys);
$objs[$index]['key'] = 5;
var_dump($objs);
- Output for 5.6.38, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array(2) {
[0]=>
array(2) {
["value"]=>
int(2)
["key"]=>
int(5)
}
[1]=>
array(2) {
["value"]=>
int(3)
["key"]=>
string(1) "b"
}
}
preferences:
99.78 ms | 408 KiB | 5 Q