TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Changing Array Key Values (http://www.talkphp.com/absolute-beginners/2822-changing-array-key-values.html)

ReSpawN 05-19-2008 09:29 PM

Changing Array Key Values
 
Well here we go again. :-P Obviously.

At the moment, I've got an array with the values 8, 4 and 2. Of course, accompanied by the keys 0, 1 and 2.
Now, since those keys can also address the roundtype, I can enter it as 1, 2 and 3. Which would be far more convenient than sending 1::8, 2::4, 3::2 and exploding it as I go.

So, how do I shift somewhat these keys?

Wildhoney 05-20-2008 12:42 AM

I wouldn't use the index as a value in the equation, purely because indexes must be unique and so when you want the same round value, you'll have to refactor your code. How about something like a multidimensional array? Such as the following...

php Code:
$aValues = array
(
    array(1, 5.5555),
    array(3, 7.7777)
);

foreach ($aValues as $aValue)
{
    echo 'Result = ' . round($aValue[1], $aValue[0]) . '<br />';
}

ReSpawN 05-20-2008 05:26 PM

Well, sort of helped I guess.

I can't figure out how to display the brackets though.

Currently I've got:
PHP Code:

    foreach (countBrackets($totalPlayers) as $key => $value) {
        
$key++;
        
$keys $key.'::'.$value[1];
        
array_push($bracketArray$keys);
    }
    
    
    
print_r($bracketArray); 

Now, this displays Array ( [0] => 1::16 [1] => 2::8 [2] => 3::4 [3] => 4::2 ) but now how I want it to.

How do I now, print out the 4 rounds, which each corresponding number of brackets in that round.
It should be displayed somewhat like this:

Code:

Round 1    Round 2    Round 3    Round 4
1          1          3          8
2                                 
3          3         
4
5          6          8
6
7
8          8

Of course, each value from 1 to 8 in the first round will be printed vertically with each an unique top: Xpx; value. Same goes for round two, but then automaticly with a new left: Xpx; and top: Xpx; value.

Well, it would be a HUGE help you you guys could help me out here.

ReSpawN 05-21-2008 05:03 PM

// Urgent bump :)

ReSpawN 05-22-2008 06:25 PM

// --->Urgent bump? Sorry, but I really need some help with this!

Kalle 05-27-2008 12:25 AM

Do you mean something like:

PHP Code:

$round 2;
$data = Array(824);

echo(
array_key_exists(--$round) ? $data[$round] : 'Invalid round'); 

Or something like that?

sketchMedia 05-27-2008 12:57 AM

Like this?
PHP Code:

<?php
function bomb($array) { return explode('::'$array); }
$bracketArray = array ( 
            
=> '1::8',
            
=> '2::4',
            
=> '3::2',
            
=> '4::1'
            
);        
$bracketArray array_map('bomb'$bracketArray);
foreach(
$bracketArray as $bracket)
{
    
    echo
'<div style="width:90px; float:left;">',
        
'<strong>Round '$bracket[0], '</strong><br />';
        
    for(
$i=0$i $bracket[1]; $i++)
    {
        echo 
'<span style="float:left;clear:both;">',$i 1,'</span>';
    }
    echo
'</div>';
}

hope i havent missed the mark

ReSpawN 05-27-2008 09:31 PM

sketch, I think I love you. That's exacly what I meant! Filling in the values will be done dynamicly, so no problem there! Thanks a lot!

Kalle, thanks for the help as well, although it was not what I meant! Non the less. :-)


All times are GMT. The time now is 04:40 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0