PHP中缺少参数错误

PHP中缺少参数错误,php,Php,我的错误是: azexo\u导航菜单\u链接\u属性()缺少参数4 这是我的代码: function azexo_nav_menu_link_attributes($atts, $item, $args, $depth) { if (strpos($atts['title'], 'mega') !== false) { $atts['title'] = str_replace('mega', '', $atts['title']); $atts['href'] = '#'; }

我的错误是:

azexo\u导航菜单\u链接\u属性()缺少参数4

这是我的代码:

function azexo_nav_menu_link_attributes($atts, $item, $args, $depth) {
if (strpos($atts['title'], 'mega') !== false) {
    $atts['title'] = str_replace('mega', '', $atts['title']);
    $atts['href'] = '#';
}
$atts['class'] = 'menu-link';
return $atts;

我怎样才能修好它?谢谢

剩下的代码在哪里?我们需要看看调用函数在哪里

无论如何,在调用函数时,应该缺少第4个参数$depth


您可以按如下方式向函数传递四个参数:
azexo\u nav\u menu\u link\u attributes($param1,$param2,$param3,$param4)
而不是
azexo\u nav\u menu\u link\u attributes($param1,$param2,$param3)
如果希望最后一个参数是可选的,则必须将其设置为某个值。试试这个:

function azexo_nav_menu_link_attributes($atts, $item, $args, $depth = null){ ... }

因此,您将能够调用函数并只发送前3个参数,或4个参数。取决于您需要什么。

可能在调用函数时添加$depth参数作为参数?显示调用代码。您在哪里调用此函数?给我们看看代码,我已经修好了,谢谢!