Lets say I have an array like:
$thing = Array
(
[test1] => something
[test2] => something
[info] => yes
[array] => Array
(
[test1] => something else
[test2] => something else
[info] => maybe
[array] => Array
(
[test1] => something
[info] => yes
)
)
)
How can I write a function that goes through $thing and adds a key to each part called ‘valid’ with a value of TRUE if the value of ‘info’ is ‘yes’ and FALSE otherwise?
I basically want the final array to look like:
$final = Array
(
[test1] => something
[test2] => something
[info] => yes
[valid] => TRUE //add this
[array] => Array
(
[test1] => something else
[test2] => something else
[info] => maybe
[valid] => FALSE //add this
[array] => Array
(
[test1] => something
[info] => yes
[valid] => TRUE //add this
)
)
)
I’m writing a library for codeigniter that manages a site map and provides easy ways to get the breadcrumb and navigation tree for a page but am stuck at a part where I need to do something like this.
The main question that I can’t figure out is:
How do I go through the array and add a key to each part? Also there can be an infinite amount of arrays in arrays.
Thanks!
You can use this
Output