{"id":173943,"date":"2013-03-22T21:19:03","date_gmt":"2013-03-22T17:19:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=173943"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=173943","title":{"rendered":"<span class=\"post_title\">\u0412 PHP 5.5 \u0431\u0443\u0434\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f array_column<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t19-\u0433\u043e \u043c\u0430\u0440\u0442\u0430 \u0431\u044b\u043b\u043e <a href=\"https:\/\/twitter.com\/dsp_\/status\/314021877565755393\">\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e<\/a> \u043e \u00abfeature freeze\u00bb \u0432 \u0432\u0435\u0442\u043a\u0435 PHP 5.5, \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 php-5.5.0beta1. \u0412 \u0447\u0438\u0441\u043b\u0435 \u0434\u0440\u0443\u0433\u0438\u0445, \u0432 \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e <a href=\"https:\/\/github.com\/php\/php-src\/pull\/257\">\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430<\/a> \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/wiki.php.net\/rfc\/array_column\">array_column<\/a>. <\/p>\n<p>  \u0423\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u043e\u0431 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/147674\/\">\u043f\u0440\u043e\u043c\u0435\u043b\u044c\u043a\u043d\u0443\u043b\u043e<\/a> \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u043f\u0440\u043e\u0448\u043b\u044b\u043c \u043b\u0435\u0442\u043e\u043c, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0438\u043c\u0435\u043b\u0430 \u0441\u0442\u0430\u0442\u0443\u0441 <i>proposed<\/i>, \u0442\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043e\u043d\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e, \u0432\u043e\u0439\u0434\u0435\u0442 \u0432 PHP 5.5.<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 array_column<\/h4>\n<p>  \u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0437\u043e\u0432\u0430: <\/p>\n<pre><code class=\"php\">(array) array_column(array $input, mixed $columnKey[, mixed $indexKey]); <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c <b>$input<\/b> \u2014 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 [N&gt;1]-\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430, \u0430 <b>$columnKey<\/b> \u2014 \u0438\u043d\u0434\u0435\u043a\u0441 \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <b>$indexKey<\/b>, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u043d\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0443.<\/p>\n<h5>\u041f\u0440\u0438\u043c\u0435\u0440 \u21161<\/h5>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<pre><code class=\"php\">&lt;?php $records = array(     array(         'id' =&gt; 2135,         'first_name' =&gt; 'John',         'last_name' =&gt; 'Doe'     ),     array(         'id' =&gt; 3245,         'first_name' =&gt; 'Sally',         'last_name' =&gt; 'Smith'     ),     array(         'id' =&gt; 5342,         'first_name' =&gt; 'Jane',         'last_name' =&gt; 'Jones'     ),     array(         'id' =&gt; 5623,         'first_name' =&gt; 'Peter',         'last_name' =&gt; 'Doe'     ) );   $firstNames = array_column($records, 'first_name'); print_r($firstNames); <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 <b>first_name<\/b>:<\/p>\n<pre><code class=\"php\">Array (     [0] =&gt; John     [1] =&gt; Sally     [2] =&gt; Jane     [3] =&gt; Peter ) <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u0440\u0438\u043c\u0435\u0440 \u21162<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 id:<\/p>\n<pre><code class=\"php\">&lt;?php $lastNames = array_column($records, 'last_name', 'id'); print_r($lastNames); <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u0438\u0434\u0430 id =&gt; last_name:<\/p>\n<pre><code class=\"php\">Array (     [2135] =&gt; Doe     [3245] =&gt; Smith     [5342] =&gt; Jones     [5623] =&gt; Doe ) <\/code><\/pre>\n<p>  \u041d\u043e \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u00ab\u0441\u0442\u0440\u043e\u043a\u0438\u00bb \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043d\u0430\u0431\u043e\u0440 \u043a\u043b\u044e\u0447\u0435\u0439?<\/p>\n<pre><code class=\"php\">&lt;?php $mismatchedColumns = array(     array(         'a' =&gt; 'foo',         'b' =&gt; 'bar',         'e' =&gt; 'baz'     ),     array(         'a' =&gt; 'qux',         'c' =&gt; 'quux',         'd' =&gt; 'corge'     ),     array(         'a' =&gt; 'grault',         'b' =&gt; 'garply',         'e' =&gt; 'waldo'     ), ); <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0435\u0441\u0442\u044c \u043a\u043b\u044e\u0447 &quot;<b>a<\/b>&quot;, \u043d\u043e \u043a\u043b\u044e\u0447 &quot;<b>b<\/b>&quot; \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u0432\u0443\u0445 \u0438\u0437 \u043d\u0438\u0445. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b <b>columnKey <\/b>\u0431\u0443\u0434\u0443\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b, \u0430 \u0435\u0441\u043b\u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043b\u044e\u0447 <b>indexKey<\/b>, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043d\u0443\u043b\u044f. \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043c\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u0431\u044b\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441.<\/p>\n<pre><code class=\"php\">&lt;?php $foo = array_column($mismatchedColumns, 'a', 'b'); $bar = array('bar' =&gt; 'foo', 'qux', 'garply' =&gt; 'grault');   \/* $foo \u0438 $bar \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:   Array (     [bar] =&gt; foo     [0] =&gt; qux     [garply] =&gt; grault ) *\/ <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 &quot;<b>b<\/b>&quot;, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0432\u0443\u043c\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u044d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441.<\/p>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>indexKey<\/b>, \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0448\u0435\u0442 \u0442\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435.<\/p>\n<pre><code class=\"php\">\/\/ \u041c\u0430\u0441\u0441\u0438\u0432 $records \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u21161 $firstNames = array_column($records, 'first_name', 'last_name'); print_r($firstNames);   \/* Array (     [Doe] =&gt; Peter     [Smith] =&gt; Sally     [Jones] =&gt; Jane ) *\/ <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/173943\/\"> http:\/\/habrahabr.ru\/post\/173943\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t19-\u0433\u043e \u043c\u0430\u0440\u0442\u0430 \u0431\u044b\u043b\u043e <a href=\"https:\/\/twitter.com\/dsp_\/status\/314021877565755393\">\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e<\/a> \u043e \u00abfeature freeze\u00bb \u0432 \u0432\u0435\u0442\u043a\u0435 PHP 5.5, \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 php-5.5.0beta1. \u0412 \u0447\u0438\u0441\u043b\u0435 \u0434\u0440\u0443\u0433\u0438\u0445, \u0432 \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e <a href=\"https:\/\/github.com\/php\/php-src\/pull\/257\">\u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430<\/a> \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/wiki.php.net\/rfc\/array_column\">array_column<\/a>. <\/p>\n<p>  \u0423\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u043e\u0431 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/147674\/\">\u043f\u0440\u043e\u043c\u0435\u043b\u044c\u043a\u043d\u0443\u043b\u043e<\/a> \u043d\u0430 \u0425\u0430\u0431\u0440\u0435 \u043f\u0440\u043e\u0448\u043b\u044b\u043c \u043b\u0435\u0442\u043e\u043c, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0438\u043c\u0435\u043b\u0430 \u0441\u0442\u0430\u0442\u0443\u0441 <i>proposed<\/i>, \u0442\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043e\u043d\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e, \u0432\u043e\u0439\u0434\u0435\u0442 \u0432 PHP 5.5.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-173943","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/173943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173943"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/173943\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}