如何存储在多维数组PHP数据 [英] How to store data in multidimensional array php

查看:271
本文介绍了如何存储在多维数组PHP数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储在二维数组。我不知道我该怎么办。
这是code这说明我在做什么:

I'm trying to store on two dimensional array. I have no idea how I do. This is the code which demonstrates what I'm doing:

$games = array("Game1" => "Team 2 vs. Team 3", "Game2" => "Team 1 vs. Win 1","Game3" => "Loser Game 1 vs. Loser Game 2","Game4" => "Win Game 2 vs. Win Game 3", "Game5" => "Win Game 4 vs. Loser Game 4 (If Loser 4 is First Loss)");  

$time = array("06:00 " => "06:30","06:30 " => " 07:00","07:00" => "07:30","07:30" =>"08:00","08:00" => "08:30","08:30" => "09:00","09:00" =>"09:30","09:30" => "10:00","10:00" => "10:30","10:30" => "11:00","11:00" =>"11:30","11:30" => "12:00");

$start_date = date_create("2015-09-21");
$start_date = date_create("2015-09-28");
$totalday = date_diff($start_date,$end_date);
$totaldays = $totalday->format("%a");
$countGames = count($games);

$game_per_day = round($totaldays / $countGames);

for($i=1;$i<=$countGames;$i++)
{
    foreach( multidimensional_array_rand( $time, $game_per_day ) as $start => $end ){
          $times[][] = $start . $end;
     }
}

不过,这种输出

Array ( [0] => Array ( [0] => 10:3011:00 ) [1] => Array ( [0] => 09:0009:30 ) [2] => Array ( [0] => 11:0011:30 ) [3] => Array ( [0] => 07:3008:00 ) [4] => Array ( [0] => 07:3008:00 ) )

和我想这样的显示它,而不是

and I want to display it like this instead

Array ([10:30] => 11:00 [09:00] => 09:30 [11:00] => 11:30 [09:00] => 09:30 [07:30] => 08:00 )

我该如何解决呢?谢谢你在前进谁帮助我..

How I can solve this ? Thank You in Advance who help to me..

推荐答案

一个简单的二维数组可能是:

A simple 2-D array might be:

$data = array(
    'Game 1' => array(
         'Name' => 'Team 1 vs Team 2',
         'Start Time' => '11:00',
         'End Time' => '12:00'
    ),
    'Game 2' => array(
         'Name' => 'Team 3 vs Team 4',
         'Start Time' => '12:00',
         'End Time' => '13:00'
    ),
    ...
);

使用,以满足您的需求适当调整。

with appropriate adjustments to suit your needs.

您可以再通过每场比赛的数据迭代。一个具体的数值可以被访问,如:

You can then iterate through the data for each game. A specific value could be accessed like:

$data['Game 1']['Start Time']

这篇关于如何存储在多维数组PHP数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆