我刚刚实现了一个代码,我使用while($row = mysqli_fetch_array($result)){
array_push($res2, array(
"name"=>$row['name'],
"publisher"=>$row['username'],
"image"=>$row['photo'],
)
);}
创建了一个数组,并且在相同的代码中我已经有了一个现有的数组。我想要做的是只使用这两个结果制作一个数组。这是第一个数组的代码:
import java.util.Random;
public class Main {
public static void main(String[] args) {
Random r1 = new Random();
Random r2 = new Random();
Random r3 = new Random();
Random r4 = new Random();
int die1 = r1.nextInt(6) + 1;
int die2 = r2.nextInt(6) + 1;
int die3 = r3.nextInt(6) + 1;
int die4 = r4.nextInt(6) + 1;
System.out.println("ROUND 1");
System.out.println("Player A rolls: " + die1 + " and " + die2 +".");
System.out.println("Player B rolls: " + die3 + " and " + die4 +".");
Integer aMax = Integer.max(die1*10 + die2, die2*10 + die1);
System.out.println("Player A's highest number is: " + aMax);
Integer bMax = Integer.max(die3*10 + die4, die4*10 + die3);
System.out.println("Player B's highest number is: " + bMax);
System.out.println("Result: " +
(!aMax.equals(bMax) ?
aMax > bMax ? "Player A wins!" : "Player B wins!"
:
"Draw!")
);
}
}
这是我的第二个阵列:
System.out.println(1 + 2 + "text"); //"3text"
System.out.println(1 + "text" + 2); //"1text3"
System.out.println("text" + 1 + 2); //"text12"
如果您有任何提示,任何评论甚至问题(如果我对您不够清楚),请问我!谢谢!
编辑: 我想要做的是这种类型的数组:
[{"名称":"用户A""出版者":"让娜""图像&#34 ;: "乌拉""" photouser"" url2a"},{"名称":"用户B" "出版者":" Jeanb""图像":" urlb"" photouser"" url2b"}]
答案 0 :(得分:0)
您需要使用第一部分中的密钥:
button.getScene().getWindow()
在此数组中,引用其他数组中的用户名:
$sql = "SELECT photoprofile,username from photo WHERE username IN ('somearray')";
$resol = array();
$resulol = mysqli_query($con,$sql);
$photos = mysqli_fetch_all($resulol, MYSQLI_ASSOC);
$photos = array_column($photos, "photoprofile", "username");
# Set the username--vvvevvvvv
foreach($restest as $username => $user) {
# Store the username as the key here for reference later
$res[$username] = (isset($photos[$user]))? $photos[$user] : '';
}
答案 1 :(得分:0)
通过使用替换技术,我终于实现了我想做的事情:
使用foreach循环,我创建了一个带参数profilepic
的数组,在另一个数组上,我创建了另一个带有默认值的参数,然后我替换了它。
我的代码:首先是我的foreach循环:
foreach ( $restest as $user ) {
if ( isset($photos[$user])) {
array_push($res1, array(
"profilepic"=>$photos[$user]));
}
else {
array_push($res1, array(
"profilepic"=>'defaultvalue'));;
};
}
然后我改变了:
while($row = mysqli_fetch_array($result)){
array_push($res2, array(
"name"=>$row['name'],
"publisher"=>$row['username'],
"image"=>$row['photo'],
"profilepic"=>'defaultvalue'
)
);}
最后我将其替换为:
$res = array_replace_recursive($res2,$res1);
所以echo json_encode($res)
的最终数组是:
[{ “名称”: “用户A”, “出版者”: “让娜”, “图像”: “乌拉”, “” profilepic “ ”url2a“},{ ”名称“: ”用户B“,” 出版者“:” Jeanb”, “图像”: “urlb”, “profilepic”, “默认值”}]