简体   繁体   English

从数组类型转换为php函数参数的字符串

[英]type casting from array to string for php function argument

I have the following snippet of code. 我有以下代码片段。

<?php
$arr = array('str' => 'arr');
var_dump(htmlspecialchars($arr));
?>

And has the following output. 并具有以下输出。

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /Users/shodoco/test.php on line 3
NULL

I am wondering why I am getting this output. 我想知道为什么我得到这个输出。 According to the PHP manual here , arrays are always converted to the string "Array". 根据此处的PHP手册,数组始终会转换为字符串“ Array”。 htmlspecialchars() takes its first argument as a string, and my understanding is the array should be implicitly converted to string "Array". htmlspecialchars()将其第一个参数作为字符串,我的理解是应将数组隐式转换为字符串“ Array”。 But in this example, I am getting NULL. 但是在这个例子中,我得到了NULL。 What happens here? 这里会发生什么?

Can you try this: 你可以尝试一下:

echo "<pre>";
print_r($yourArray);
echo "<pre>";

don't change anything on there, just keep the array as is, i find this the best way of inspecting arrays as strings. 不要在那里更改任何内容,只是将数组保持原样,我发现这是将数组作为字符串检查的最佳方法。

hope that answers your query? 希望能回答您的疑问?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM