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 回答