I have the following array structure:
$this->entity += [
$key => [
'column' => $column,
'required' => $required,
'type' => $type,
'value' => $value,
'valueIfNull' => $valueIfNull,
'useDBDefaultWhenNull' => $useDBDefaultWhenNull
]
];
var_dump($this->entity);
array(13) {
["id"]=>
array(6) {
["column"]=>
string(2) "fk_tbl_users_id"
["required"]=>
bool(false)
["type"]=>
array(2) {
[0]=>
string(7) "integer"
[1]=>
int(1)
}
["value"]=>
string(0) ""
["valueIfNull"]=>
string(0) ""
["useDBDefaultWhenNull"]=>
bool(true)
}
["isAdmin"]=>
array(6) {
....
}
}
I need to be able to find the $key from a given $column value. I've tried the following, but of course, doesn't work:
$entity_key = array_search('fk_tbl_users_id', $this->entity, true);
I've also tried to make my $entity array with this structure (ommiting the keys 'column' etc):
$this->entity += [
$key => [
$column,
$required,
$type,
$value,
$valueIfNull,
$useDBDefaultWhenNull
]
];
var_dump($this->entity);
array(13) {
["id"]=>
array(6) {
[0]=>
string(2) "fk_tbl_users_id"
[1]=>
bool(false)
[2]=>
array(2) {
[0]=>
string(7) "integer"
[1]=>
int(1)
}
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
bool(true)
}
["isAdmin"]=>
array(6) {
....
}
}
Am I doing something wrong? I am assuming not, and the ONLY way I'll be able to retrieve the key is by force looping my array, get the 'column' value, compare it against a $col value, if true, then keep the $key and break my loop. Something like this:
private function getKeyname(string $col)
{
foreach ( $this->entity as $key => $value )
{
$key_colname = $value[0]; // or $value['column'], depending on array structure I end up using
if ( $key_colname === $col ) return $key;
}
}
I would of preferred not having to loop my array and use PHP builtin functions, if at all possible?
Thanks for your inputs!!
Pat.