用php中的变量替换字符串

时间:2014-08-30 18:42:06

标签: php string wordpress variables

我在Wordpress插件中有以下代码:

wp_localize_script('ffd_js_script', 'myAjax', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'idinfo' => $myoptionValue[idinfo],
            'index1' => $myoptionValue[id1],
            'index2' => $myoptionValue[id2]
            )
        );

我想替换

'index1' => $myoptionValue[id1],
'index2' => $myoptionValue[id2]

for($i=1; $i<= $myoptionValue[fieldcount]; $i++)
        {
            $arguments .= ',"index"'.$i.'=>'.$myoptionValue[id.$i];
        }

所以我有

        wp_localize_script('ffd_js_script', 'myAjax', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'idinfo' => $myoptionValue[idinfo]
            $arguments
            )
        );

显然我认为它可能就像这样简单,但它不是,我的错误在哪里?

编辑:

完整(正常)代码:

require( plugin_dir_path( __FILE__ ) . 'menu.php');
    require_once( plugin_dir_path( __FILE__ ) . 'getuser.php');

    add_action( 'wp_enqueue_scripts', 'ffd_load_scripts' );

    function ffd_load_scripts()
    {
        $myoption =  get_option( 'fixformdata_options' );
        $myoptionValue = maybe_unserialize( $myoption );  

        wp_register_script('ffd_js_script', WP_PLUGIN_URL.'/FixFormData/js/ffd_js_script.js', array('jquery'));
        wp_localize_script('ffd_js_script', 'myAjax', array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'idinfo' => $myoptionValue[idinfo],
            'index1' => $myoptionValue[id1],
            'index2' => $myoptionValue[id2]
            )
        );

        wp_enqueue_script('jquery');
        wp_enqueue_script('ffd_js_script', plugin_dir_url(__FILE__) . 'js/ffd_js_script.js');

0 个答案:

没有答案