0

コードの 2 つの部分をマージしようとしています。そのためには、複数回呼び出す関数からのエコーされた配列列出力を、計算を実行できる配列に格納する必要があります。

これが私がやろうとしていることです:

<?php

$searchquery[1] ="jupiter";
$searchquery[2] ="venus";
//can be multiple queries

include ('find.php');

for($i=0;$i<count($searchquery);$i++)
{
find($searchquery[$i]);
}

/find.php echoes back to me a MySQL query which then
 creates a 2 dimensional array for me called
/$searchresult which looks like this as an example
t x (let's call first column t for example, and second x)
|1|3|
|1|4|
|2|6|
|4|8|
|7|1|

and it echoes it back to me, this works.

But, i need to use the first column (t) (11247) output from find.php
which was the result of the searchquery "jupiter", 
and i need to store it as some sort of array in this  current sheet,
theni need to store the "venus" searchquery which is let's say

t x 
|1|3| 
|2|4|
|3|4|
|4|6|
|5|4|

この現在のシートに最初の列 (t) を配列として格納します。

現在のシートで次の操作を実行できるように、find.php 関数からのエコーを配列として保存しようとしています。

$venusarrayt = array(1, 1, 2, 4, 7); //the manually defined
 //$searchresult first column output from find.php which echos to me (t) (11247)
 $jupiterarrayt = array(1, 2, 3,4,5); //the manually defined 
 //$searchresult first column output from find.php which echos to me (t) (12345)

//I need to perform the following operation and sum all of the t combinations

for($l=0;$l<count($venusarrayt);$l++){
for($s=0;$s<count($jupiterarrayt);$s++){
echo $venusarrayt[$l]+$jupiterarrayt[$s];

この部分は機能します!$searchresultしかし、エコーされた出力を上記の for ループを実行できる配列にマージするのに問題があります。この例では、php シートに「venusarrayt and jupiterarrayt」と入力して手作業で行っています。

複数回呼び出す関数からのエコーされた配列列の結果を配列に格納する方法があると確信していますが、その方法はまだわかりません。助けてください。

4

3 に答える 3

0

これがお役に立てば幸いです。

<?php

$searchquery[0] ="jupiter";
$searchquery[1] ="venus";
//can be multiple queries

include ('find.php');
$results=null;
for($i=0;$i<count($searchquery);$i++)
{
  $temp=find($searchquery[$i]);
  $results[$i]=$temp[t];
}



for($l=0;$l<count($results[1]);$l++){
 for($s=0;$s<count($results[0]);$s++){
  echo $results[1][$l]+$results[0][$s];
  }
 }
于 2012-05-03T12:16:12.910 に答える
0

検索されたデータをさらに操作するための明確なソリューションは、次のようになります。

$searchquery[1] ="jupiter";
$searchquery[2] ="venus";

$search_result = array(); $i=0;
foreach($searchquery as $current_query){
  $current_result = FindResul($current_query);
  // FindResult will be your function which process single query and returns result of it
  $search_result[$i]['query'] = $current_query;
  $search_result[$i]['result'] = $current_result;
  $i++;
}

上記のコードを実行すると、構造が明確で操作しやすい配列 2-レベル配列が得られます。データを比較したり、必要な方法で表示したりするために使用できます。

結果の配列は次のような構造になります。

$search_result[0]['query'] = 'jupiter';
$search_result[0]['result'] = '...jupiter resul';

$search_result[1]['query'] = 'venus';
$search_result[1]['result'] = '...venus result';
于 2012-05-03T13:10:02.670 に答える
0

問題を解決するには、ネストされた配列を作成する必要があります。

$searchquery[1] ="jupiter";    
    $searchquery[2] ="venus";

for($i=1;$i<=count($searchquery);$i++){
  $temp=find($searchquery[$i]);
  $results[$i]=$temp[t];
}

$k=$i;
for($z=0;$z<=$i;$z++){
    $total='';
    for($p=0;$p<=$k;$p++){
        $total=$total+$results[$p][$z];
    }
    echo $total;
    echo "\n";
}

function find($word){
    return array('t' => array('1', '2', '4', '7'));
}

答えは次のようになります。

Array
(
    [1] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 4
            [3] => 7
        )

[2] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 4
        [3] => 7


    )

)
2
4
8
14

このソリューションは、最初の結果、2番目の結果など、n個のすべてのクエリを追加します........

于 2012-05-03T13:04:50.350 に答える