您好,我在我的 wp 网站中使用了这段代码
function theme_files() {
$scripts = [
// ['handle' => 'date', 'src'=>'jquery.ui.datepicker-cc.all.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'date', 'src'=>'js-persian-cal.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'paralax', 'src'=>'jquery.fullpage.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'fullslud', 'src'=>'jquery.superslides.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'carousel', 'src'=>'owl-carousel.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'mmenu', 'src'=>'jquery.mmenu.min.all.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'lightbox', 'src'=>'lightbox.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'masonry', 'src'=>'masonry.pkgd.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'template', 'src'=>'theme.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true],
['handle' => 'selectbox', 'src'=>'select2.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true]
];
for ($i=0; $i < sizeof($scripts); $i++) {
wp_enqueue_script( $scripts[$i]['handle'], get_template_directory_uri() . '/js/' . $scripts[$i]['src'], $scripts[$i]['dep'], $scripts[$i]['ver'] );
}
}
但是我的客户将他的网站迁移到使用旧版本 php 的主机上,我得到语法错误
我需要将这个数组转换为旧版本。 谁能帮帮我?
最佳答案
使用以下结构:
$scripts = array(
array('handle' => 'date', 'src'=>'js-persian-cal.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true),
array('handle' => 'paralax', 'src'=>'jquery.fullpage.min.js','dep'=> array( 'jquery' ),'var'=> false,'in_foot'=> true)
);
我有同样的问题并将我的数组转换为旧结构。
foreach($scripts as $script){
wp_enqueue_script( $script['handle'], get_template_directory_uri() . '/js/' . $script['src'], $script['dep'], $script['ver'] );
}
关于php - 将数组从 php 5.3 转换为 php 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47028197/