-1

この PHP 配列を必要な文字列形式に変換するのに苦労しています。

$result = mysql_query($query) or die(mysql_error());

$result1 = array();

while($row = mysql_fetch_array($result)){

  $result1[strtotime($row['DOB'])][strtotime($row['DOB'])] = strtotime($row['DOB']);

  $result1[strtotime($row['DOB'])]['PRICE'] += $row['PRICE'];



}
print_r($result1);

現在の出力は次のとおりです。

[1136246400] => Array
    (
        [1136246400] => 1136246400
        [PRICE] => 165.5
    )

 [1136332800] => Array
    (
        [1136332800] => 1136332800
        [PRICE] => 169.5
    )

そして、私はそれが必要です:

   Array ( [0] => [1136246400, 165.5] [1] => [1136332800, 169.5] )

PHP の初心者 - どんな助けでも大歓迎です。ありがとう。

4

1 に答える 1

0

私が理解している限り、以下のようなものが必要です。

$i = 0;
while($row = mysql_fetch_array($result)){
  $result1[$i][0] = strtotime($row['DOB']);
  // to avoid warning in $result1[$i][1] += $row['PRICE']; 
  if(!isset($result1[$i][1]))
     $result1[$i][1] = 0;
  // -----------
  $result1[$i][1] += $row['PRICE'];
  $i++;
}
print_r($result1);
于 2013-03-26T15:38:45.787 に答える