当我尝试为面向对象方法创建循环时(我想),php会提示我两个错误。我认为它必须做一些事情($args
) 不能用于我应该注入字符串的地方,但我找不到答案。我应该在foreach中运行foreach循环吗?
This is the case:
我有一个文件名为themeScripts.php 其中我返回array();
像这样:return array(
\'custom\' => array(
\'src\' => \'/includes/js/custom.js\',
\'deps\' => \'jquery\',
\'ver\' => \'4.0\',
\'in_footer\' => true
),
\'selecter\' => array(
\'src\' => \'/includes/js/jquery.fs.selecter.min.js\'
\'deps\' => \'jquery\'
\'ver\' => false,
\'in_footer\' => true
)
);
在此之后,我想运行foreach循环,以便定义函数的循环wp_enqueue_script
像这样:public function loadScripts() {
// Include themeScripts from config
$themeScripts = include(dirname(__FILE__) . "/../config/themeScripts.php");
// Loop trough each themeScript
foreach($themeScripts as $handle => $args):
wp_enqueue_script( $handle, $args);
endforeach;
}
警告:preg\\u match()要求参数2为字符串,数组在/Users/username/Sites/sitename/public\\u html/themename/wp includes/class中给定。wp脚本。php在线128警告:strpos()要求参数1为字符串,数组在/Users/username/Sites/sitename/public\\u html/themename/wp includes/class中给出。wp脚本。php在线128