插件在运行循环时显示致命错误

时间:2018-08-03 13:52:07

标签: php wordpress

我正在创建一个插件,当我将for-each循环作为激活钩子运行时,它显示致命错误,但是当我运行不带循环的代码时,它运行正常。

Blew是我正在使用的代码:

function wp_create_table_insert_data()
{
    global $wpdb;

$state_name= ["Andaman and Nicobar Islands","Andhra Pradesh","Assam","Bihar","Chandigarh","Chhattisgarh","Dadra and Nagar Haveli","Daman and Diu","Delhi","Goa","Gujarat","Haryana","Himachal Pradesh","Jammu and Kashmir","Jharkhand","Karnataka","Kerala","Lakshadweep","Madhya Pradesh","Maharashtra","Manipur","Meghalaya","Mizoram","Nagaland","Odisha","Puducherry","Punjab","Rajasthan","Sikkim","Tamil Nadu","Telangana","Tripura","Uttar Pradesh","Uttarakhand","West Bengal"];


    $table_name = $wpdb->prefix.'state';

foreach ($state_name as $row){
    $wpdb->insert($table_name, array('state_name' => $row));
}
}

0 个答案:

没有答案