草庐IT

encoded_array

全部标签

php - json_encode 返回浮点值,就好像它是

我需要将数组转换为json并希望保留数据的精度和类型。$a=array("num"=>10000.00);print_r(json_encode($a));在上面的例子中,10000.00被转换为10000。我怎样才能保留json中的所有内容。 最佳答案 在php5.6+中你能做的最好的事情就是确保它被编码为float。但是,这并不能保持精度:10000.00);print_r(json_encode($a,JSON_PRESERVE_ZERO_FRACTION));如果数据类型和精度很重要,您需要发送一个额外的参数,例如:$a=[

php - fatal error : Call to a member function getAttributes() on array

我一直在做这个google身份验证教程,以更好地了解如何使用googlesigninapi,但我最近收到了这个错误:Fatalerror:CalltoamemberfunctiongetAttributes()onarray.每当我尝试:$this->client->verifyIdToken()->getAttributes();在getPayload()函数中。我不知道为什么会这样。我的配置是Windows10,我正在使用WAMP服务器来运行这个应用程序。任何帮助将不胜感激。client=$googleClient;$this->client->setClientId('234sf

php - 给出的错误 : array_flip() expects parameter 1 to be array, 字符串

我是Laravel的新手,遇到以下错误,array_flip()expectsparameter1tobearray,stringgiveninGuardsAttributes.phpline188atHandleExceptions->handleError(2,'array_flip()expectsparameter1tobearray,stringgiven','/Users/aaronmk2/Desktop/CodingDojo/php/onetoone/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Con

php - array_count_values 我想回显一个特定的键值

我忙于一家网上商店,我想回复一下今天有多少订单需要交付我有一个循环,其中包含以下代码:$winkels[]=$vendor->id;这很好,因为我做了以下代码:echo''.print_r(array_count_values($winkels),true).'';比我得到的结果:Array([63]=>1[45]=>1[85]=>1[59]=>1)结果很好,但是我怎么能回显id:63的值呢?有人能帮帮我吗? 最佳答案 对于单例:-$data=array_count_values($winkels);echo$data[63];对于

php - SimpleHTMLDom : Call to a member function find() on array

所以我想在大型html页面中循环遍历特定的TD。我正在使用simplehtmldom来实现这一目标。问题是如果不把每一步都放在foreach中,我就无法让它工作。这是我的phpinclude('../inc/simple_html_dom.php');$html=file_get_html("http://www.bjork-family.com/f43-london-stories");//IjustputthedomofpagebodyintoTEST$test=$html->find('#page-body');foreach($test->find('img')as$eleme

php - PHP 在 array_map() 函数中使用关键字的目的?

我的应用程序中有以下几行代码。谁能告诉我在以下array_map()函数中use关键字的目的是什么?array_map(function($record)use($edit_form,$otherfields,$otherfields_keys){User::parseData($record,$edit_form['metadata']);if(isset($otherfields[$record['user_id']])){return$record+$otherfields[$record['user_id']];}return$record+$otherfields_keys;

php - 在 PHP 中使用 array_chunk 移动元素

我有一个基本数组,我在其中使用array_chunk将其分成3个元素。$array=array('a','b','c','d','e','f','g','h');$chunk=array_chunk($array,3);结果如下[["a","b","c"],["d","e","f"],["g","h"]](Lasblock有2个元素)如果最后一个“block”只有2个元素,我怎样才能将第一个block的元素向下移动以便第一个元素有2个?它应该是这样的:[["a","b",],["c""d","e",],["f""g","h]](第一个block有2个元素)

php - 在什么场景下使用json_encode()比使用serialize()更好?

这就是我要问的全部内容。查看PHP手册,看到一个用户帖子说serialize比json_encode慢45-90%(他运行了一些基准测试)。但是“慢”到底有多慢呢?我可以找到很多“对抗”的东西,但没有一个像我这样的初学者可以涉及。我刚刚写了一个脚本,用json编码一个数组,另一个脚本解码它。我对序列化做了同样的事情。显然,这不会告诉我它们之间有任何显着差异。 最佳答案 (每次)执行10,000次,以(希望)对内存使用和CPU时间的差异有一个可衡量的想法。大多数情况下,性能方面的差异并不显着。在两种特定情况下使用JSON非常有用:返回

php - 如何在没有 PHP 5.2 的情况下使用 json_encode

我编写了一个CMS,它使用PHP函数json_encode通过Ajax请求发回一些数据。不幸的是,我试图将它加载到运行PHP5.1版的服务器上,json_encodePHP函数在5.2.0之前的PHP版本上不可用。有谁知道不使用内置的json_encode函数就可以将PH数组编码为JSON的方法吗?编辑我用过Pekka的函数,但现在我发现JQuery不会按预期解析结果。即使Firebug显示JSON被传回。我的Firebug窗口如下所示:我的jquery看起来像这样:$.ajax({type:"GET",url:"includes/function/add_users.php",dat

arrays - "Can' t use function return value in write context”PHP错误

Fatalerror:Can'tusefunctionreturnvalueinwritecontextinline3,在什么情况下会触发此类错误?我的程序://QUERYVARIABLE$query="select*formuserwhereuser_name='$user_name'anduser_password='sha($user_password)'";//ESTABLISHINGCONNECTION$result=mysqli_query($dbc,$query)ordie('ErrorQueryingDatabase');while($row=mysqli_num_ro