CodeIgniter Forums
Array helper: dot search - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Array helper: dot search (/showthread.php?tid=81764)



Array helper: dot search - iRedds - 04-25-2022

The dot_array_search() function has strange behavior.

I am expecting a value that matches the key, or null if the key is not found. But

PHP Code:
dot_array_search('a.b.c', ['a' => ['b' => ['c' => 'c']) // return "c". Ok
dot_array_search('a.b.c', ['a' => ['b' => ['c']) // return "null". Ok. because the key "c" does not exist.

dot_array_search('a.b.c', ['a' => ['b' => 'b']) // return "b". why? key "c" does not exist and should return "null"

//but if we replace "b" with wildcard "*"
dot_array_search('a.*.c', ['a' => ['b' => 'b']) // return "null". Ok 
dot_array_search('a.*.c', ['a' => ['b' => []]) // return "null". Ok 

//but 
dot_array_search('a.*.c', ['a' => []) // return "empty array" ?? 



RE: Array helper: dot search - ignitedcms - 04-26-2022

I haven't really looked at it, but is the function expecting the user to at least provide an array with the correct number of levels? You'll have to wait for a CI4 to elaborate.


RE: Array helper: dot search - pvt - 04-29-2022

Find exact you must use function array_deep_search()

Code:
array_deep_search('a.b.c', ['a' => ['b' => 'b']]);  //return b
array_deep_search('a.*.c', ['a' => []]); //return NULL



RE: Array helper: dot search - kenjis - 04-30-2022

I don't know why.

I created an issue.
https://github.com/codeigniter4/CodeIgniter4/issues/5939

I concluded this is a bug, and sent a PR:
https://github.com/codeigniter4/CodeIgniter4/pull/5940