snipt

Ctrl+h for KB shortcuts

Text only

Yii2 Array Map to Model

$categories = ArrayHelper::map(Category1::find()->where(['class_id' => $class_id])->all(), 'category_1_id', 'name');
https://snipt.net/embed/4b6b292e9d5b1e3b741e1fbf84732d34/
/raw/4b6b292e9d5b1e3b741e1fbf84732d34/
4b6b292e9d5b1e3b741e1fbf84732d34
text
Text only
1
2024-05-08T07:56:32
True
False
False
Feb 09, 2021 at 08:09 PM
/api/public/snipt/115/
yii2-array-map-to-model
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>$categories = ArrayHelper::map(Category1::find()-&gt;where([&#39;class_id&#39; =&gt; $class_id])-&gt;all(), &#39;category_1_id&#39;, &#39;name&#39;); </span></pre></div> </td></tr></table>
yii
1
2
3
4
--- 
+++ 
@@ -0,0 +1 @@
+$categories = ArrayHelper::map(Category1::find()->where(['class_id' => $class_id])->all(), 'category_1_id', 'name');