0

多次元配列で類似のタイトルを見つけて、それらのタイトルを印刷しようとしています。

配列ダンプ:

Array ( [0] =>
 Array ( [test] => 1 [CdnEnabled] => true [Ver] => 4.1   [Size] => 646586847 [Title] => test1 [TitleId] => 0 [GroupId] => 12 )
 [1] => Array ( [test] => 1 [ed] => true  [Ver] => 4.1 [Size] => 637972836 [Title] => test1[TitleId] => 0 [GroupId] => 12 ) 
 [2] => Array ( [test] => 1[ed] => true [Ver] => 4.0.1  [Size] => 779055727 [Title] => test2[TitleId] => 0 [GroupId] => 12 ) 
 [3] => Array ( [test] => 1[ed] => true [Ver] => 4.0.1  [Size] => 779055727 [Title] => test2[TitleId] => 0 [GroupId] => 12 ) 
 [4] => Array ( [test] => 1[ed] => true [Ver] => 4.0.1  [Size] => 779055727 [Title] => test3[TitleId] => 0 [GroupId] => 12 ) 
 [5] => Array ( [test] => 1[ed] => true [Ver] => 4.0.1  [Size] => 779055727 [Title] => test3[TitleId] => 0 [GroupId] => 12 ) 
 [6] => Array ( [test] => 1[ed] => true [Ver] => 4.0.1  [Size] => 779055727 [Title] => test4[TitleId] => 0 [GroupId] => 12 ) 
 [7] => Array ( [test] => 1[ed] => true [Ver] => 4.0.1  [Size] => 779055727 [Title] => test4[TitleId] => 0 [GroupId] => 12 ) 
 )

PHPコード:

function getrecursiveValues($start, $arrayValues, $totalCount, $previousTitle, $newtotalCount = 0)
{
  $currentTitle = $arrayValues[$i]['Title'];
  if ($currentTitle == "Panorama Base Images") {
    print_r($newAray);
  }


  for ($i = $start; $i < $newtotalCount; $i++) {
    echo "<h1> i is $i  new totalcount is $newtotalCount </h1>";
    if (($newtotalCount != 0) && ($i == ($newtotalCount - 1))) {
      echo "<br />in ifffffffffffffffffffffffffffff<br />";
      $currentTitle  = $arrayValues[$i]['Title'];
      $previousTitle = $arrayValues[$i - 1]['Title'];

      if ($previousTitle == $currentTitle) {
        echo "sameeeeee" . $currentTitle . "<br />";
        break 1;
      } else {
        break 1;
      }

    } else {
      echo "<br />in elseee<br />";
      $currentTitle = $arrayValues[$i]['Title'];
      if ($i == 0) {
        echo "<h1>  $currentTitle</h1>";
      }

      if ($i != $start)
        $previousTitle = $arrayValues[$i - 1]['Title'];
      echo "previous val is  -- $previousTitle";

      if ($previousTitle == $currentTitle) {
        echo "sameeeeee" . $currentTitle . "<br />";            
      } else {
        $nn = count($arrayValues);
        echo "<h2><br /> calling the recursivie from the function total isssssss $totalCount---- </h2> <br />";

        $newtotalCount = 0;
        $newAray       = array_slice($arrayValues, $i);
        $newtotalCount = count($newAray);

        $previousTitle = $newAray[0]['Title'];

        if ($totalCount >= $newtotalCount)
          getrecursiveValues(0, $newAray, $newtotalCount, $previousTitle, $newtotalCount);
        else
          return;

      }
    }

  }
  echo "<h1> Out of for</h1>";
  return "bye";
  exit;  
}

私は機能から抜け出すことができません、誰かがこれで私を助けることができますか?

4

1 に答える 1

0

スペルが間違っていたら、このようなものを使ってみましたか?

function recursive($array) {
   foreach($arrays as $array) {
    if(is_array($array) == true) 
       $array = recursive($slimer aray);
     } else {
       //do what ever you gotta do
   }
  }
}
于 2012-09-17T00:15:27.897 に答える