Laravel convert resultset to array

时间:2017-08-30 20:14:30

标签: php arrays laravel-5.4

Database table <div id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01_t" class="ms-menubuttoninactivehover ms-displayBlock" title="Open Menu" onmouseover="MMU_PopMenuIfShowing(this);MMU_EcbTableMouseOverOut(this, true)" hoveractive="ms-menubuttonactivehover ms-rteThemeBackColor-3-1 ms-displayBlock" hoverinactive="ms-menubuttoninactivehover ms-displayBlock" onclick="if (document.getElementById('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00').childNodes.length == 0) { MMU_CallbackPreMenuOpen('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00', 'm_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01', 'WebForm_DoCallback(\'m_sqlRsWebPart$RSWebPartToolbar$ctl00$RptControls$RSActionMenu$ctl01\',\'enabled\',MMU_CallbackHandler,\'__CALLBACKCONTEXT__\',MMU_CallbackErrHandler,true)', 60000, 'The request for menu items from the server has timed out.', event); } CoreInvoke('MMU_Open',byid('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00'), MMU_GetMenuFromClientId('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01'),event,true, null, 300); return false;" foa="MMU_GetMenuFromClientId('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01')" oncontextmenu="ClkElmt(this); return false;" style="white-space:nowrap"><a class="ms-menu-a" id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01" href="javascript:;" title="Open Menu" style="cursor:pointer;white-space:nowrap;" onfocus="MMU_EcbLinkOnFocusBlur(byid('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00'), this, true);" onkeydown="MMU_EcbLinkOnKeyDown(byid('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00'), MMU_GetMenuFromClientId('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01'), event);" onclick="if (document.getElementById('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00').childNodes.length == 0) { MMU_CallbackPreMenuOpen('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00', 'm_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01', 'WebForm_DoCallback(\'m_sqlRsWebPart$RSWebPartToolbar$ctl00$RptControls$RSActionMenu$ctl01\',\'enabled\',MMU_CallbackHandler,\'__CALLBACKCONTEXT__\',MMU_CallbackErrHandler,true)', 60000, 'The request for menu items from the server has timed out.', event); } CoreInvoke('MMU_Open',byid('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl00'), MMU_GetMenuFromClientId('m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01'),event,true, null, 300); return false;" oncontextmenu="ClkElmt(this); return false;" menutokenvalues="" serverclientid="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_ctl01" callbackinprogress="" menuitemsdisabled="" menuitemshidden="" menuitemschecked=""><span class="sqlrv-ActionMenuText sqlrv-ToolBarMenuCell">Actions</span><img src="/_layouts/images/blank.gif" style="border:0px" alt="Use SHIFT+ENTER to open the menu (new window)."></a><img class="ms-viewselector-arrow" src="/_layouts/images/menudark.gif" alt="Open Menu"></div> has many columns. One of them is <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_Export" type="submenu" text="Export" callbackitem="true"><ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_Export_Label" type="label" menugroupid="2147483647" enabled="true" checked="false"></ie:menuitem><ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_XML" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;XML&quot;);" text="XML file with report data" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;XML&quot;);" text_original="XML file with report data" valorig=" "></ie:menuitem> <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_CSV" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;CSV&quot;);" text="CSV (comma delimited)" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;CSV&quot;);" text_original="CSV (comma delimited)" valorig=" "></ie:menuitem> <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_PDF" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;PDF&quot;);" text="PDF" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;PDF&quot;);" text_original="PDF" valorig=" "></ie:menuitem> <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_EXCELOPENXML" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;EXCELOPENXML&quot;);" text="Excel" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;EXCELOPENXML&quot;);" text_original="Excel" valorig=" "></ie:menuitem> <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_IMAGE" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;IMAGE&quot;);" text="TIFF file" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;IMAGE&quot;);" text_original="TIFF file" valorig=" "></ie:menuitem> <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_WORDOPENXML" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;WORDOPENXML&quot;);" text="Word" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;WORDOPENXML&quot;);" text_original="Word" valorig=" "></ie:menuitem> <ie:menuitem id="m_sqlRsWebPart_RSWebPartToolbar_ctl00_RptControls_RSActionMenu_MHTML" type="option" onmenuclick="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;MHTML&quot;);" text="MHTML (web archive)" callbackitem="true" menugroupid="2147483647" enabled="true" checked="false" onmenuclick_original="$find(&quot;m_sqlRsWebPart_ctl00_ReportViewer&quot;).exportReport(&quot;MHTML&quot;);" text_original="MHTML (web archive)" valorig=" "></ie:menuitem> </ie:menuitem> . I need all the <?php args = array( 'post_type' => 'product', 'posts_per_page' => 20, 'meta_key' => 'pa_tire-type', 'orderby' => 'meta_value_num', 'order' => 'asc' ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?> s as an array since it has to be fed to a method which accepts only a string array.

What I tried so far is:

SITE

But this doesn't produce the result I want. I need site_id to be like site_id

Please suggest a way to get this done. A solution based on Eloquent is also OK for me.

Thanks

2 个答案:

答案 0 :(得分:1)

Try this:

{
    cats
    dogs
}

reference pluck

referen toArray

答案 1 :(得分:0)

If you open a manual, you will see that

The n <- 3 r <- rle(as.integer(x == 0)) r$values[r$values == 1 & r$lengths < n] <- 0 r <- rle(inverse.rle(r)) group <- integer(length(x)) start <- 1 for(i in seq_along(r$values)){ group[start:(start + r$lengths[i] - 1)] <- c(1L, rep(0L, r$lengths[i] - 1)) start <- start + r$lengths[i] } method will always return an r <- rle(as.integer(x == 0)) r$values[r$values == 1 & r$lengths < n] <- 0 # This is the simplification group <- c(1L, diff(inverse.rle(r)) != 0) res <- split(x, cumsum(group)) res <- res[-which(sapply(res, function(y) all(y == 0)))] res #$`1` #[1] 1.00000 1.00000 2.00005 1.00000 1.00000 # #$`3` #[1] 1 2 0 3 4 # #$`5` #[1] 1 2 3 1 3 of results

So, there's no need to use self.mapView.showAnnotations(self.mapView.annotations, animated: true) , as result is already an array.

To get values as array of names you can do:

select

Using array here is optional, as you can iterate over ->toArray() (which is a $site_ids = DB::table('site_tab')->pluck('site_id'); ) with a ->toArray() too.