gpt4 book ai didi

php - 如何将数组转换为带索引的字符串

转载 作者:行者123 更新时间:2023-11-29 00:29:01 24 4
gpt4 key购买 nike

我想像这样转换一个数组:

 array ( [1_1] => 1 [1_2] => 2 [1_3] => 3 [1_4] => 4 [1_5] => 5 )

像这样的字符串:

"1_1-1/1_2-2/1_3-3/1_4-4/1_5-5"

我该怎么做?

我需要我的 MySQL 数据库中的索引和值。

我尝试了 implode() 但这是结果:

1/2/3/4/5

谢谢

最佳答案

$out = "";
foreach($arr as $k => $v) {
$out .= "$k-$v/";
}
$out = substr($out, 0, -1); //this line will remove the extra '/'

关于php - 如何将数组转换为带索引的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17478871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com