如何在 PHP 二维多维数组上移动 X 和 Y 轴?

发布于 2024-11-07 20:21:38 字数 691 浏览 0 评论 0原文

假设我有一个像这样的多维数组:

$data[0]['country'] = Angola
$data[0]['report'] = Food safety

$data[1]['country'] = Angola
$data[1]['report'] = Police

$data[2]['country'] = Zimbabwe
$data[2]['report'] = Water

$data[3]['country'] = Angola
$data[3]['report'] = Safety

$data[4]['country'] = Tanzania
$data[4]['report'] = Etc...

什么是最容易移动轴的,这样我就可以

$data['country'][0] = Angola
$data['country'][1] = Angola
$data['country'][2] = Zimbabwe
$data['country'][3] = Angola
$data['country'][4] = Tanzania

$data['report'][0] = Food safety
$data['report'][1] = Police
$data['report'][2] = Water
$data['report'][3] = Safety
$data['report'][4] = Etc...

say I have a multidimensional array like this:

$data[0]['country'] = Angola
$data[0]['report'] = Food safety

$data[1]['country'] = Angola
$data[1]['report'] = Police

$data[2]['country'] = Zimbabwe
$data[2]['report'] = Water

$data[3]['country'] = Angola
$data[3]['report'] = Safety

$data[4]['country'] = Tanzania
$data[4]['report'] = Etc...

What is the easiest to shift the axes, so that I would have

$data['country'][0] = Angola
$data['country'][1] = Angola
$data['country'][2] = Zimbabwe
$data['country'][3] = Angola
$data['country'][4] = Tanzania

$data['report'][0] = Food safety
$data['report'][1] = Police
$data['report'][2] = Water
$data['report'][3] = Safety
$data['report'][4] = Etc...

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

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

发布评论

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

评论(2

嘿看小鸭子会跑 2024-11-14 20:21:38
$result = array();
foreach($data as $value){

   $result['country'][] = $value['country'];
   $result['report'][] = $value['report'];
}
$data = $result;
$result = array();
foreach($data as $value){

   $result['country'][] = $value['country'];
   $result['report'][] = $value['report'];
}
$data = $result;
ヤ经典坏疍 2024-11-14 20:21:38
for ($i=0; $i < (count($data) / 2); $i++)
{
  $data['country'][$i] = $data[$i]['country'];
  $data['report'][$i] = $data[$i]['report'];
}
for ($i=0; $i < (count($data) / 2); $i++)
{
  $data['country'][$i] = $data[$i]['country'];
  $data['report'][$i] = $data[$i]['report'];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文