array-filter

IE 11 Script1002 Filter syntax error

╄→尐↘猪︶ㄣ 提交于 2019-12-10 13:45:56
问题 Hi there I get a error message in ie11 but not in chrome the error is Script1002 Syntax error My code is as follows vm.NoOftroopMemEditReq = (vm.EventAttendees.TicketAttendees.filter(a => a.Attendees.some(Attendee => Attendee.IsEditRequired === true))).length; 回答1: in IE 11 this symbol => don't work, replace => with === vm.NoOftroopMemEditReq = (vm.EventAttendees.TicketAttendees.filter(function (a) { return a.Attendees.some(Attendee === Attendee.IsEditRequired === true); })).length; 来源: https

Filter multidimensional array by value in array [duplicate]

£可爱£侵袭症+ 提交于 2019-12-08 11:40:40
问题 This question already has answers here : How to filter an array by a condition (7 answers) Closed 3 years ago . This is my array: $myArray = array( array("name"=>"Andrea", "Age"=>17), array("name"=>"Tresna", "Age"=>20), array("name"=>"Aria", "Age"=>12) ); I want to filter that multi array by value in array. This is my filter: $filter = array("Andrea", "Aria"); So the result must be like this: $newArray = array( array("name"=>"Andrea", "Age"=>17), array("name"=>"Aria", "Age"=>12) ); how to do

Array_filter in the context of an object, with private callback

折月煮酒 提交于 2019-12-03 23:22:27
I want to filter an array, using the array_filter function. It hints at using call_user_func under water, but does not mention anything about how to use within the context of a class/object. Some pseudocode to explain my goal: class RelatedSearchBlock { //... private function get_filtered_docs() { return array_filter($this->get_docs(), 'filter_item'); } private filter_item() { return ($doc->somevalue == 123) } } Would I need to change 'filter_item' into array($this, 'filter_item') ? Is what I want possible at all? Yes: return array_filter($this->get_docs(), array($this, 'filter_item')); See

Filter some values from an array in a serialized post_meta (PHP)

别等时光非礼了梦想. 提交于 2019-12-02 07:58:40
问题 I have setup in Wordpress a custom post type ( Artists )... I have a plugin that serializez the meta information from the Artists .. and i need to filter this information by channel ..: "channel";s:6:"trance" which is also in the serialized meta "show_data" 'a:1:{s:32:"57fba1b113187b95554339a0737e0309";a:7:{s:7:"dj_name";s:7:"DjValue";s:9:"show_name";s:9:"ShowValue";s:7:"channel";s:6:"trance";s:10:"show_image";s:0:"";s:4:"time";s:1:"0";s:8:"time_end";s:1:"0";s:4:"mon1";s:1:"1";}}' The plugin

Filter some values from an array in a serialized post_meta (PHP)

一曲冷凌霜 提交于 2019-12-02 04:24:26
I have setup in Wordpress a custom post type ( Artists )... I have a plugin that serializez the meta information from the Artists .. and i need to filter this information by channel ..: "channel";s:6:"trance" which is also in the serialized meta "show_data" 'a:1:{s:32:"57fba1b113187b95554339a0737e0309";a:7:{s:7:"dj_name";s:7:"DjValue";s:9:"show_name";s:9:"ShowValue";s:7:"channel";s:6:"trance";s:10:"show_image";s:0:"";s:4:"time";s:1:"0";s:8:"time_end";s:1:"0";s:4:"mon1";s:1:"1";}}' The plugin unserializez the data like this : foreach ( $djs as $dj ) { $temp = maybe_unserialize( get_post_meta(

Remove empty fields in an array after foreach in PHP

坚强是说给别人听的谎言 提交于 2019-12-01 14:25:11
I am new to PHP. This is my code from our mailing.php. When a user submits a request, there are 5-7 select-able fields and 20-25 fields that end up not being selected. The output lists all fields and values regardless of whether they are empty or have been selected. I understand I need to use either unset or array_filter , but cannot figure out how and where I need to insert into code. if($_POST && count($_POST)) { $body = ''; foreach($_POST as $key=>$value) $body .= $key . ": " . $value . "\r\n"; mail("email@email.com", "Email Received at email@email.com", $body); You can try this if($_POST &

Remove empty fields in an array after foreach in PHP

。_饼干妹妹 提交于 2019-12-01 12:24:56
问题 I am new to PHP. This is my code from our mailing.php. When a user submits a request, there are 5-7 select-able fields and 20-25 fields that end up not being selected. The output lists all fields and values regardless of whether they are empty or have been selected. I understand I need to use either unset or array_filter , but cannot figure out how and where I need to insert into code. if($_POST && count($_POST)) { $body = ''; foreach($_POST as $key=>$value) $body .= $key . ": " . $value . "

PHP: How to identify AND CHANGE duplicate values in an array?

自作多情 提交于 2019-11-30 16:16:22
OK, there are a lot of examples of duplicate detection and removal in php arrays, using array_unique() etc but what if you want to find dups, modify them, check again in a loop until all dups are now unique? I think it's something like using array_filter()... so as a more specific example, here's what would come out of a sql statement something like this: SELECT id, list.comboname FROM list INNER JOIN ( SELECT comboname FROM list GROUP BY comboname HAVING count(id) > 1 ) dup ON list.comboname = dup.comboname To an array of the duplicates in the table: Array ( [0] => 49 [1] => big.dup [2] =>

PHP: How to identify AND CHANGE duplicate values in an array?

為{幸葍}努か 提交于 2019-11-29 22:53:14
问题 OK, there are a lot of examples of duplicate detection and removal in php arrays, using array_unique() etc but what if you want to find dups, modify them, check again in a loop until all dups are now unique? I think it's something like using array_filter()... so as a more specific example, here's what would come out of a sql statement something like this: SELECT id, list.comboname FROM list INNER JOIN ( SELECT comboname FROM list GROUP BY comboname HAVING count(id) > 1 ) dup ON list.comboname

Array_filter and empty()

北慕城南 提交于 2019-11-29 11:59:00
Warning: array_filter() expects parameter 2 to be a valid callback, function 'empty' not found or invalid function name.... Why is empty considered a invalid callback? $arr = array_filter($arr, 'empty'); This works: if(empty($arr['foo'])) die(); Answer empty() is not a function but a language construct and array_filter() can only accept a function as its callback. This is given as a small note on the manual page: Note: Because this is a language construct and not a function, it cannot be called using variable functions Work around To work around this you can wrap empty in another function for