farshadf's avatar

how to check if an array has subkey in laravel test

hi , i have a multi dimention array that i want to write test for . i read on web that there was a function called arrayHasSubKey but it does not exists any more it seems . i am using laravel 5.8 and i want to check if this array has a subkey this is what my array looks like :

key =>value [
 key2 =>value2 [
  key3 => [
    key4 =>value4,
    key5=>value5
]
]
]

now i want to check if key2 or key3 exists on the array . how can that be done in a laravel test . thanks in advance

0 likes
1 reply
sr57's avatar

In 3 times

-1- use php function array_flip to reverse keys & values

-2- use Laravel function flattern to get the keys

-3-use what you want (for instance Laravel function filter) to test

Please or to participate in this conversation.