What I'm trying to do is get the key from the array values that are in sequence, like 1,2,3, 4... or 7,8,9... I'm able to do it just with two keys as you can see here:
$spots = array("1|250x60","2|120x60","4|250x60","6|120x60","7|120x60","8|120x60");
$c=count($spots);
//First I explode each item on the array and divide them into 2 arrays, one for the spot number and the other for the banner size
$i=0;
foreach($spots as $key=>$value)
{
$a=explode("|",$value);
$nums[$i] = $a[0];
$sizes[$i] = $a[1];
$i++;
}
reset($nums);
reset($sizes);
for($i=0;$i<$c;$i++)
{
//Here I check for the sequence
if( ($nums[$i]+1) == @$nums[$i+1] )
{
print "Sequence: ".$nums[$i]."=>".$nums[$i+1]."<Br>";
print "You can also combine spot ".$nums[$i]."(".$sizes[$i].") with spot ".$nums[$i+1]."(".$sizes[$i+1]."), having just one spot of ";
$g=explode("x",$sizes[$i]);
$g2=explode("x",$sizes[$i+1]);
print $g[0] + $g2[0]."x".$g[1]."<br>";
}
}
If you guys can help me do it using my code or think in a better/different way to do it, please let me know.
Thanks a lot