2016-07-05 61 views
0

你能帮助我吗?我有这样一行:Php退出()函数打印消息

$orderRequest = new CreateOrderRequest(null, "BTC", null, $currency, $amount, $orderDescription, "en", $callbackUrl, $successUrl, $cancelUrl); 

我需要打印:$orderRequest

我不喜欢这样写道:

​​

也许还有一个更简单的方法来做到这一点?

+1

唯一的print_r ($ orderRequest) –

+0

这取决于你想达到的目标。从我的角度来看,这看起来很好。但很难判断这是否是你正在做的事情的最佳方式,因为我们看不到剩下的代码,除了'exit'语句之外不知道发生了什么 –

+0

这看起来不对对我来说,你实际上并没有打印'$ orderRequest',只是你发送给它的构造函数的变量。除此之外,你可能想发回一些东西,接收端可以做些事情,比如html或json。 – jeroen

回答

2

这里的简化方式:

echo '<pre>'; // easy way to improve print_r layout (newlines) 
print_r($orderRequest); // can print objects and arrays, while exit() doesn't 
exit(); // optional, depending if you want to terminate program execution 

此外,大括号像{$currency}只在需要时打印在双引号的字符串对于使用数组键像echo "{$currency['key']}";