Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript函数本身的php代码中使用javascript变量?_Javascript_Php - Fatal编程技术网

如何在javascript函数本身的php代码中使用javascript变量?

如何在javascript函数本身的php代码中使用javascript变量?,javascript,php,Javascript,Php,我想使用javascript变量作为php数组的索引来获取php数组元素。我试过下面这个方法,但不起作用 // I want to get value of $arr[0] and here array index is a javascript variable <script type="text/javascript"> function select_seller() { d = document.getElementById('seller_id').value;

我想使用javascript变量作为php数组的索引来获取php数组元素。我试过下面这个方法,但不起作用

// I want to get value of $arr[0] and here array index is a javascript variable

<script type="text/javascript">
function select_seller()
{
    d = document.getElementById('seller_id').value;
    document.write("<?php echo  $arr['<script>document.write(d)</script>'];?>");
}
</script>
//我想得到$arr[0]的值,这里数组索引是一个javascript变量
功能选择\u卖方()
{
d=document.getElementById('seller_id')。值;
文件。填写(“”);
}

请帮帮我,你不能这么做。PHP代码首先执行,因此一旦用户加载页面,PHP就无法检测JavaScript变量


如果您发布了更多的代码,我们可能会告诉您如何使用JavaScript执行您正在尝试执行的操作。

您似乎不知道服务器端和客户端之间的区别,您的php代码会在服务器上进行解释,以生成html数据并将其发送到浏览器以呈现给用户,因此,您不能在客户端使用php函数。。php角色是准备数据并将数据发送到客户端。 因此,无论您在这里试图实现什么,您都可以选择使用ajax调用从服务器获取数据,并在接收数据时使用js进行处理