Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop
Showing
3 changed files
with
44 additions
and
3 deletions
framework @ 119c247f
@@ -108,11 +108,51 @@ class ClassModel | @@ -108,11 +108,51 @@ class ClassModel | ||
108 | foreach ($classesData as $val) { | 108 | foreach ($classesData as $val) { |
109 | foreach ($val['ca'] as $single) { | 109 | foreach ($val['ca'] as $single) { |
110 | $classes[$single['id']] = $single['name']; | 110 | $classes[$single['id']] = $single['name']; |
111 | - $classes += array_column($single['sub'], 'name', 'id'); | 111 | + $classes += self::array_column($single['sub'], 'name', 'id'); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | return $classes; | 115 | return $classes; |
116 | } | 116 | } |
117 | + | ||
118 | + | ||
119 | + /** | ||
120 | + * 自定义array_column函数 | ||
121 | + * | ||
122 | + * @return array 返回数组中指定的一列组成的数组 | ||
123 | + */ | ||
124 | + /** | ||
125 | + * 自定义array_column函数 | ||
126 | + * @param array $input 需要取出数组咧的多维数组 | ||
127 | + * @param string $columnKey 需要返回的列 | ||
128 | + * @param mixed $indexKey 作为返回数组的索引值 | ||
129 | + * @return array 从多维数组中返回单列数组 | ||
130 | + */ | ||
131 | + private static function array_column(array $input, $columnKey, $indexKey = null) | ||
132 | + { | ||
133 | + $array = array(); | ||
134 | + foreach ($input as $value) { | ||
135 | + if ( ! isset($value[$columnKey])) { | ||
136 | + trigger_error("Key \"$columnKey\" does not exist in array"); | ||
137 | + return false; | ||
138 | + } | ||
139 | + if (is_null($indexKey)) { | ||
140 | + $array[] = $value[$columnKey]; | ||
141 | + } | ||
142 | + else { | ||
143 | + if ( ! isset($value[$indexKey])) { | ||
144 | + trigger_error("Key \"$indexKey\" does not exist in array"); | ||
145 | + return false; | ||
146 | + } | ||
147 | + if ( ! is_scalar($value[$indexKey])) { | ||
148 | + trigger_error("Key \"$indexKey\" does not contain scalar value"); | ||
149 | + return false; | ||
150 | + } | ||
151 | + $array[$value[$indexKey]] = $value[$columnKey]; | ||
152 | + } | ||
153 | + } | ||
154 | + return $array; | ||
155 | + | ||
156 | + } | ||
117 | 157 | ||
118 | } | 158 | } |
-
Please register or login to post a comment