array_push key=>value ,怎么办?
我想将键和值推送到数组中,但我无法
$con = mysqli_connect('localhost','root','','wp') or die (mysqli_error('Error:'));
$query = mysqli_query($con,'set names utf8')or die (mysql_error());
$qy = mysqli_query($con,"SELECT ID,post_title FROM wp_posts WHERE post_type='page' AND post_status='publish'")or die (mysql_error());
$arr = array();
while ($row = mysqli_fetch_array($qy)){
$id = "?page_id=".$row['ID'];
$title = $row['post_title'];
$arr[] = $id . "=>" . $title;
array_push($arr, "$id" => "$title");
}
帮助我..
谢谢^_^
I want to push key and value in array , but I can't
$con = mysqli_connect('localhost','root','','wp') or die (mysqli_error('Error:'));
$query = mysqli_query($con,'set names utf8')or die (mysql_error());
$qy = mysqli_query($con,"SELECT ID,post_title FROM wp_posts WHERE post_type='page' AND post_status='publish'")or die (mysql_error());
$arr = array();
while ($row = mysqli_fetch_array($qy)){
$id = "?page_id=".$row['ID'];
$title = $row['post_title'];
$arr[] = $id . "=>" . $title;
array_push($arr, "$id" => "$title");
}
plz help me ..
thanks ^_^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我会做的:
然后当您需要打印它们时:
不要在数组中存储不必要的信息(即:
?page_id=
)。Here's what I would do instead:
And then when you need to print them:
Don't store unnecessary information (ie:
?page_id=
) in arrays.您想要执行
$arr[$id] = $title
吗?或者你想要这个:前者将使
$arr
包含$id=>$title
。如果有多个,后者将使$arr
包含$id=>array($title1,$title2,$title3)
等。Do you want to do
$arr[$id] = $title
? Or do you want this:The former will make it so that
$arr
contains$id=>$title
. The latter will make it so that$arr
contains$id=>array($title1,$title2,$title3)
etc if there are multiples.