[英]Assign PHP variables in array
I'm working on integrating external code. 我正在集成外部代码。 Following is the code: 以下是代码:
if(count($_POST))
pay_page(array('key'=>'gtKFFx','txnid'=>'shanil','amount'=>'100');
There are static values. 有静态值。 I want to assign php variables to this array: 我想将php变量分配给此数组:
if(count($_POST))
pay_page(array('key'=>'gtKFFx','txnid'=><?php echo $b; ?>,'amount'=>'10');
How do I achieve that? 我该如何实现? Can somebody help? 有人可以帮忙吗?
if(count($_POST))
pay_page(array('key'=>'gtKFFx','txnid'=> $b,'amount'=>'10'));
This should work. 这应该工作。
Just write there $b
, no <?php
etc. You are in PHP script, so there is no reason why to begin PHP script again. 只需在其中写入$b
,没有<?php
等。您使用的是PHP脚本,因此没有理由再次启动PHP脚本。
if(count($_POST))
pay_page(array('key' => 'gtKFFx', 'txnid' => $b, 'amount' => 10));
Note: 注意:
- There was missing bracket at the end of the script -脚本末尾缺少括号
- amount is number, so it should be written without quotes. -数量是数字,因此应写成无引号。
If you are in out of php script ie your code is correct. 如果您不在php脚本中,即您的代码正确。
Now you are in php script only. 现在,您仅处于php脚本中。 so echo is not required. 因此不需要回声 。
so just use like below code: 所以只需使用下面的代码:
if(count($_POST))
pay_page(array('key' => 'gtKFFx', 'txnid' => $b, 'amount' => 10));
I think this is useful. 我认为这很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.