Php 数组到格式化文本键:值

发布于 2024-12-07 17:35:19 字数 687 浏览 1 评论 0原文

我有这个数组:

Array ( [location] => Array ( [country] => India [country_code] => IN [region] => [region_code] => [city] => [zip] => [latitude] => 13.044468 [longitude] => 77.575665 [ip_address] => 123.236.219.154 [timestamp] => 1317496122 [route] => 3rd Cross Rd [neighborhood] => Basaveshwara Layout [sublocality] => BCITS PVT LTD [locality] => Bengaluru [administrative_area_level_2] => Bengaluru Rural [administrative_area_level_1] => Karnataka ) ) 

我想知道是否有一种方法可以将其格式化,如下所示:

country: India
country_code:In

就像 键:值键:值键:值

I have this array:

Array ( [location] => Array ( [country] => India [country_code] => IN [region] => [region_code] => [city] => [zip] => [latitude] => 13.044468 [longitude] => 77.575665 [ip_address] => 123.236.219.154 [timestamp] => 1317496122 [route] => 3rd Cross Rd [neighborhood] => Basaveshwara Layout [sublocality] => BCITS PVT LTD [locality] => Bengaluru [administrative_area_level_2] => Bengaluru Rural [administrative_area_level_1] => Karnataka ) ) 

I wonder if there is a way that I can format it some what like this:

country: India
country_code:In

That is like
Key : Value,
Key : Value,
Key : Value

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

层林尽染 2024-12-14 17:35:19

类似的事情?

foreach( $array as $key => $value ) {
  echo $key." : ".$value.",";
}

您必须检查最后一个值并删除“,”。

Something like that?

foreach( $array as $key => $value ) {
  echo $key." : ".$value.",";
}

You have to check the last value and remove the "," then.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文