Sunday 15 March 2015

nested - Extracting values from arrays in custom fields -


I am trying to come up with an array of values ​​for all specific custom fields. The price itself is also an array. I have tried all kinds of array functions, but I have not come in right or right combination, so far my code is:

  $ args = array (' Post_type '= & gt;' match_report ',' post_status' = & gt; 'publish', 'meta_query' = & gt; array ('relationship' = & gt; 'OR', array ('key' = & gt; ; 'Report_home-scores'), array ('key' => 'report_ar-scores'))); $ Reportcore = new WP_Query ($ Args); $ Scorer result = array (); If ($ ReportCorry-> is_pause ()) {While ($ ReportCore-> POS ()) {$ reportscore-> The_post (); $ Homescorers = get_post_meta ($ post-> ID, 'report_home-scorers', incorrect); $ Awayscorers = get_post_meta ($ post-> ID, 'report_away-scorers', incorrect); Forex Currency ($ homescorers as $ homescorer) {array_push ($ scorer results, $ homescorer); } Foreign exchange ($ awayscorers $ awayscorer) {array_push ($ scorer result, $ awayscorer); }? & Gt; & Lt ;? Php} wp_reset_postdata (); // andif} ///////////// Function remove_empty ($ array) {return array_filter ($ array, '_remove_empty_internal'); } Function _remove_empty_internal ($ value) {return! Empty ($ value) || $ Value === 0; }   

What do I get here if I print_r ($ scorerResults); :

  array ([1] = & gt; Array ([0] => 1 [1] => 63) [2] = & gt; Array ([0] = & gt; 263 [1] => 195) [3] => Array ([0] = & gt;) [4] = & gt; Array ([0] = & Gt;))   

I just want to assume in an array the inner arrays.

Assume that you get the get score $$ array array (1,63,263,195) You can use the array_readuce function like this:

  collect functions ($ lhs, $ Rhs) {foreach ($ rhs) $ key = & gt; $ Value) if $ ($ value) $ lhs [] = $ value; $ Lhs return; } $ Scorer result = array_reduce ($ scorer result, "gather", array ());   

I'm not sure what is the empty values ​​in your third and fourth arrays and how they should be handled, so that you may have to change ($ value) To check the condition of something different. As it stands, it will also clearly filter zero scores.

No comments:

Post a Comment