问题描述
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
当我尝试将这些标题与我的数据库进行匹配并获取每个标题的 ID 时,我只能获取第一项的 ID。
["3D Printing"," 3D Architecture"," .NET Micro Framework"]
它应该返回这样的东西
["d21c6805-8780-4726-ba1d-12c9c3a28d0a"]
["d21c6805-8780-4726-ba1d-12c9c3a28d0a","1234...","567...]
code
有什么建议吗?
PS:我最好的猜测是数组中的第 2 项和第 3 项有空格,这可能会导致问题$a = $request->input('tags');
$b = str_replace(['[',']'],null,$a);
$comingTags = explode(',',$b);
$iddss = Tag::whereIn('title',$comingTags)->pluck('id');
return response()->json($iddss);
不确定是否是这个原因。
更新
我已经尝试过 "{SPACE IS HERE}3D Architecture"
但我现在得到的只是 $b = str_replace([',' '],['',''],$a);
更新 2
通过使用 []
,它确实从我的字符串中删除了空格,但也删除了我的标题单词之间的空格,因此 $b = str_replace(['[',']',$a);
变为 3D Architecture
并且因此我也无法匹配标题我的数据库在 3DArchitecture
中,因为我的数据库标题是 $iddss = Tag::whereIn('title',$comingTags)->pluck('id');
,而我试图与之匹配的是 3D Architecture
。
对此有什么建议吗?
更新 3
3DArchitecture
.
$a = $request->input('tags');
// return
"[3D Printing,3D Architecture,.NET Micro Framework]"
.
$b = str_replace(['[',$a);
// return
"3D Printing,.NET Micro Framework"
解决方法
要摆脱空白,你可以这样做
/**
*
* @author techieExpress
*
* You are given a list of n-1 integers and these integers are in the range * of 1 to n.
* Input: Given an array of n elements which contains elements
* from 0 to n-1,with any of these numbers appearing any number of times.
*
* Goal: To find these repeating numbers in O(n) and using only constant * * memory space.
**/
public class findDuplicates {
public static void main(String args[])
{
int arr[] = { 2,1,2 };
for (int i = 0; i < arr.length; i++) {
arr[arr[i] % arr.length]
= arr[arr[i] % arr.length]
+ arr.length;
}
System.out.println("The repeating elements are : ");
for (int i = 0; i < arr.length; i++) {
//System.out.print(numRay[i]);
if (arr[i] >= arr.length * 2) {
System.out.println(i + " ");
arr[i]=arr[i]%arr.length;
}
}
}
}
(credits)
whereIn 需要一个数组,所以这应该可以工作
array_map('trim',$a);