Short project description: I need to output specific values from an existing array for a tabbed alphabetical navigation. The navigation groups several letters together into tabs (i.e. 'A-C') and then displays all links to posts starting with those letters. The navigation is created by a plugin, so I need to create variables to output the groups.
What I have: I have an array which is sorted in alphabetical order by the name
key of the child array. It looks like the following example:
Array (
[0] => Array (
['name'] => 'Alpha'
['link'] => 'http://www.someurl.com'
)
[1] => Array (
['name'] => 'Alpha2'
['link'] => 'http://www.someotherurl.com'
)
[2] => Array (
['name'] => 'Beta'
['link'] => 'http://www.someurl.com'
)
[3] => Array (
['name'] => 'Delta'
['link'] => 'http://www.someotherurl.com'
)
[4] => Array (
['name'] => 'Zephyr'
['link'] => 'http://www.someurl.com'
)
)
What I think needs to happen: I need to create 5 new arrays that group these child arrays alphabetically. Meaning, I need to get all arrays whose name
starts with 'A' - 'C' into one array, 'D' - 'G' into another, etc.
In other words, the array shown above would result in the follow being created:
$a_c = array(
[0] => Array (
['name'] => 'Alpha'
['link'] => 'http://www.someurl.com'
)
[1] => Array (
['name'] => 'Alpha2'
['link'] => 'http://www.someotherurl.com'
)
[2] => Array (
['name'] => 'Beta'
['link'] => 'http://www.someurl.com'
)
);
$d_g = array(
[0] => Array (
['name'] => 'Delta'
['link'] => 'http://www.someotherurl.com'
)
);
$h_l = array();
$m_r = array();
$s_t = array();
$u_z = array(
[0] => Array (
['name'] => 'Zephyr'
['link'] => 'http://www.someurl.com'
)
);
If a new array value such as [5] => Array (['name'] => 'Kappa' ['link'] => 'http://www.someurl.com')
gets added to the first array, it will be added to the array in the $h_l
variable.
Does anyone know how or if this can be done?