Andrew Fletcher published: 18 May 2022 1 minute read
To sort through a multidimensional array seems to be a function that I occasionally call on. Handy to have referenced here:
/**
* Loop through a multi dimensional array
*
* @param array $haystack
* Data array.
*/
protected function sortMultiDimensionalArray($haystack)
{
foreach ($haystack as $key => $item) {
// If $item is an array and the number of children is greater to one
// keep looping through the array.
if (is_array($item) && count($haystack[$key]) > 1) {
$this->sortMultiDimensionalArray($haystack[$key]);
}
// If count is equal to one then load it in to the get_value array.
elseif (is_array($item) && count($haystack[$key]) == 1) {
$k = key($item);
if (is_array($item[$k])) {
$k2 = key($item[$k]);
$this->get_value[] = $item[$k][$k2];
}
else {
$this->get_value[] = $item[$k];
}
}
// Not an array.
elseif (!is_array($item)) {
$this->get_value[] = $item;
}
}
}
Related articles
Andrew Fletcher
•
18 Mar 2024
Notice: Only variables should be passed by reference in load_view_block_content()
Working through the following errorNotice: Only variables should be passed by reference in load_view_block_content() (line 391 of /var/www/vhosts/{domain}/httpdocs/themes/custom/{theme}/{theme}.theme.theme)If you want to read the full error, scroll to the bottom in Appendix. The related...
Andrew Fletcher
•
15 Mar 2024
Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Input value "f" contains a non-scalar value
Using Drupal 10, VIews, Solr and Facets has post upgrade to version 10, created the following issueSymfony\Component\HttpKernel\Exception\BadRequestHttpException: Input value "f" contains a non-scalar value. in Symfony\Component\HttpKernel\HttpKernel->handle() (line 83 of...
Andrew Fletcher
•
15 Mar 2024
Could not apply patch! Skipping
Attempting to apply a patch in Drupal 10.2.4 that had been working until this version. Now I'm seeing the following errorCould not apply patch! Skipping. The error was: The process "patch '-p1' --no-backup-if-mismatch -d '/Users/andrewfletcher/Sites/codebales/modules/contrib/facets' <...