{"id":7112,"date":"2015-01-25T08:38:08","date_gmt":"2015-01-25T00:38:08","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7112"},"modified":"2015-01-25T09:00:24","modified_gmt":"2015-01-25T01:00:24","slug":"php-array_filter","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7112","title":{"rendered":"php array_filter\u5bf9\u6570\u7ec4\u8fdb\u884c\u8fc7\u6ee4"},"content":{"rendered":"<p>\u5c06\u4e00\u4e2a\u6570\u7ec4\u4e2d\u80fd\u88ab 3 \u6574\u9664\u7684\u6570\u4fdd\u7559\u4e0b\u6765\uff0c\u9700\u8981\u5199\u56de\u8c03\u51fd\u6570\uff0c\u6ee1\u8db3\u6761\u4ef6\u7684\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false<\/p>\n<pre>    $arr = array(1,261,262,263,264,265,266,267,268,269,270,271,272,273,275,274,276,279,277,280,278,281,282,287,283,288,289);\r\n    function myFun($var){\r\n        if($var%3==0)\r\n            return true;\r\n        else\r\n            return false;\r\n    }\r\n\r\n    $filtered = array_filter($arr,\"myFun\");\r\n    print_r($filtered); \r\n<\/pre>\n<p>\u4e0a\u9762\u9488\u5bf9\u7684\u662f value, \u53ef\u4ee5\u53ea\u9488\u5bf9 key \u6216\u9488\u5bf9 key, value \u8fdb\u884c\u8fc7\u6ee4<\/p>\n<p>http:\/\/php.net\/manual\/en\/function.array-filter.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06\u4e00\u4e2a\u6570\u7ec4\u4e2d\u80fd\u88ab 3 \u6574\u9664\u7684\u6570\u4fdd\u7559\u4e0b\u6765\uff0c\u9700\u8981\u5199\u56de\u8c03\u51fd\u6570\uff0c\u6ee1\u8db3\u6761\u4ef6\u7684\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false $arr = array(1,261,262,263,264,265,266,267,268,269,270,271,272,273,275,274,276,279,277,280,278,281,282,287,283,288,289); function myFun($var){ if($var%3==0) return true; else return false; } $filtered = array_filter($arr,&#8221;myFun&#8221;); print_r($filtered); \u4e0a\u9762\u9488\u5bf9\u7684\u662f value, \u53ef\u4ee5\u53ea\u9488\u5bf9 key \u6216\u9488\u5bf9 key, value \u8fdb\u884c\u8fc7\u6ee4 http:\/\/php.net\/manual\/en\/function.array-filter.php<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-7112","post","type-post","status-publish","format-standard","hentry","category-life"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7112"}],"version-history":[{"count":5,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7112\/revisions"}],"predecessor-version":[{"id":7117,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7112\/revisions\/7117"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}