By michalczernik on
Hello Drupal comunity,
I've tried to fix TaxonomyMenu+PathAuto issue. It "almost" works... Just need to solve this:
I'm trying to access array through foreach and change values for particular key.
I'm able to access array without reference, but when I add& to create reference I receive:
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /home/.../modules/taxonomy_menu/taxonomy_menu.inc on line 185
My code:
foreach ($items as &$menu_item){
$menu_item['path'] = drupal_get_path_alias( 'taxonomy/term/' . end(explode('/',$menu_item['path'])) );
}
unset ($menu_item);
Regarding to http://uk3.php.net/foreach this should work:
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
I'm really confused and can't figure it out... ???
Any way around? Can I access array value directly (from within fereach) and change it?
Could anyone with better knowlegde of PHP help me/us please?
Comments
You do not say which version
You do not say which version of PHP you are using, the by reference feature is part of PHP 5.
You can do something similar without the need for a reference like this
Thank you NEVETS, my hosting
Thank you NEVETS,
my hosting provider claims we use PHP 5, but phpinfo() says we use PHP 4.2.6. :-(
So I've used $key instead of referencig...
TaxonomyMenu & PathAuto issue solved
to make this two modules working together I've added following code to taxonomy_menu.inc in function _taxonomy_menu_menu() just almost at the end before return $items; (about line 180):
It works for me perfectly! And it's much easier fix than http://drupal.org/node/41476#comment-181146 (which didn't work for me anyway).
Which file do I add this code
Which file do I add this code to?
Thanks