从数据标记到jQuery的php数组值

从数据标记到jQuery的php数组值,php,jquery,Php,Jquery,我正在尝试从数据标记到jQuery获取数组值,但不起作用。 这是我的密码: //$b is taking names from text-area separated by comma. $a = array_map('trim', explode(",", $b)); return <input type="text" id="pct"><button id="pcthit">submit</button><p id="pct_avail">&l

我正在尝试从数据标记到jQuery获取数组值,但不起作用。 这是我的密码:

//$b is taking names from text-area separated by comma.
$a = array_map('trim', explode(",", $b));
return <input type="text" id="pct"><button id="pcthit">submit</button><p id="pct_avail"></p></span>
<input type="hidden" id="storageElement" data-storeIt="'.$a.'">';


$("#pcthit").click(function(){
    var pstcde = $("#pct").val();
    var retrieved_string = [];
    var retrieved_string = $("#storageElement").data('storeit');
    if((pstcde != '') && (jQuery.inArray(pstcde, retrieved_string) >= 0 )){
    $("#pct_avail").html('hello');
    }
});
/$b从用逗号分隔的文本区域中提取名称。
$a=数组_映射('trim',explode(“,”,$b));
返回提交

'; $(“#pcthit”)。单击(函数(){ var pstcde=$(“#pct”).val(); 检索到的var_字符串=[]; 检索到的var_string=$(“#storageElement”).data('storeit'); if((pstcde!='')和&(jQuery.inArray(pstcde,检索的字符串)>=0)){ $(“#pct_avail”).html('hello'); } });
您需要使用
json\u encode()
对数组进行编码

return'提交

';
谢谢Barmar,我试过使用json_encode(),但仍然不起作用$(“#pct_avail”).html(检索到的_字符串);只提供了括号“[”。我将输入的所有引号(“”)替换为('),并将(')替换为(“),现在它可以工作了。非常感谢您的帮助:),我只是更改了
data storeIt
值周围的引号,因为
json\u encode()
在所有嵌入字符串周围使用双引号。哇,这是一种简单的方法,而不是更改所有引号,谢谢:)
return '<input type="text" id="pct"><button id="pcthit">submit</button>
        <p id="pct_avail"></p></span>
        <input type="hidden" id="storageElement" data-storeIt=\''.json_encode($a).'\'>';