{"id":3403,"date":"2022-10-25T09:01:50","date_gmt":"2022-10-25T09:01:50","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3403"},"modified":"2023-01-25T10:16:36","modified_gmt":"2023-01-25T10:16:36","slug":"distinct_by","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3403","title":{"rendered":"Distinct_by"},"content":{"rendered":"\n<p>Distinct_by removes duplicated items based on the key defined and returns distinct elements from the array.<\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">array distinct(array $input, &amp;key_function)<\/code><\/pre>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$input:<\/strong> The array which to make distinct.<br><strong>&amp;key_function:<\/strong> Path to the value to distinct by.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"inputA\": [\n        { \"name\": \"Bob\", \"id\": 0 },\n        { \"name\": \"Ann\", \"id\": 0 },\n        { \"name\": \"Joe\", \"id\": 1 },\n        { \"name\": \"Xavier\", \"id\": 1 }\n    ]\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    result: distinct_by(inputA, &amp;id)\n}<\/code><\/pre>\n\n\n\n<pre title=\"Result\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"result\": [\n        {\n            \"name\": \"Bob\",\n            \"id\": 0\n        },\n        {\n            \"name\": \"Joe\",\n            \"id\": 1\n        }\n    ]\n}<\/code><\/pre>\n\n\n\n<p>The function evaluates the duplicates with the defined key parameter in an array and returns the first distinct value. In the above example, The function removes duplicates in the array &#8220;inputA&#8221; with the key parameter &#8220;id&#8221; and returns the first distinct value of the array. <\/p>\n\n\n\n<p>The function has two parameters. The input data (the array in which the distinct function is applied) and the Key_function ( the parameters to distinct by) and returns an array of data where the result of the property is distinct.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Distinct_by removes duplicated items based on the key defined and returns distinct elements from the array. Syntax Parameters $input: The array which to make distinct.&amp;key_function: Path to the value to distinct by. Example The function evaluates the duplicates with the defined key parameter in an array and returns the first distinct value. In the above [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":271,"menu_order":32,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3403"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3403"}],"version-history":[{"count":9,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3403\/revisions"}],"predecessor-version":[{"id":3829,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3403\/revisions\/3829"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}