草庐IT

array_filter

全部标签

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 - filter_var 与 preg_match

早上好我正在转换我正在处理的网站以与最新版本的PHP兼容,因此我正在检查并用未折旧的等效项替换所有ereg实例。然而,有人告诉我有一个名为filter_var的方便的PHP内置函数。我的问题是,使用filter_var而不是preg_match是否有意义?至于选择一个而不是另一个是否有性能提升或任何其他好处,如果有的话,它们是什么? 最佳答案 首先,关于过滤的PHP手册页:https://php.net/manual/en/book.filter.php其次,上下文是关键。一般来说,过滤器函数被设计为使用外部输入(标量或数组),或内

php - Zend_Form 和 Zend_Filter

如何在重新填充之前禁用Zend_Form中的过滤? 最佳答案 您不能禁用它们。你可以这样做:$filters=$form->getElementFilters();$form->setElementFilters(array());$form->populate($data);$form->setElementFilters($filters);但是,afaikZend_Form只会在您从表单中获取值时过滤值,而不是在您填充表单时过滤值,因此以上内容毫无意义。如果您追求原始值,请使用$form->getUnfilteredValue

php - filter_var($url, FILTER_VALIDATE_URL) 使用哪个正则表达式 php?

filter_var($url,FILTER_VALIDATE_URL)似乎是检测$url是否包含url的好方法。有什么办法可以看出这个函数检测的是什么正则表达式?谢谢 最佳答案 它使用其他东西而不是正则表达式。在C中,它检查php_url_parse_ex()(C)函数的返回值,您可以在以下位置查看:ext/standard/url.c,line97,调用ext/filter/logical_filters.c,line440.用这些术语来说:如果您在PHP中调用parse_url()(PHP),并执行与php_filter_va

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

php - in_array 组合值 ('test' ,'value' )

我正在尝试将in_array或类似的东西用于关联数组或更复杂的数组。这是普通的in_arrayin_array('test',array('test','exists'));//truein_array('test',array('not','exists'));//false我要搜索的是对,例如“test”和“value”的组合。我可以根据需要将要搜索的组合设置为array('test','value')或'test'=>'value'。但是,如果要搜索的数组是,我该如何进行搜索?array('test'=>'value','exists'=>'here');orarray(arra