简体   繁体   中英

converting array from php 5.3 to php 4

hi i use this code in my wp site

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'] );    

}
}

but my customer migrate his website to a host with old version of php and i get syntax error

and i need to convert this array to old version. can any one help me?

Use from following structure:

$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)
);

I had same issue and converted my arrays to old structure.

foreach($scripts as $script){
    wp_enqueue_script(  $script['handle'], get_template_directory_uri() . '/js/' .  $script['src'],  $script['dep'],  $script['ver'] );    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM