TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-19-2008, 09:29 PM   #1 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default Changing Array Key Values

Well here we go again. 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?
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 05-20-2008, 12:42 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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 />';
}
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-20-2008, 05:26 PM   #3 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

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.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 05-21-2008, 05:03 PM   #4 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

// Urgent bump :)
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 05-22-2008, 06:25 PM   #5 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

// Urgent bump? Sorry, but I really need some help with this!
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 05-27-2008, 12:25 AM   #6 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

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?
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
The Following User Says Thank You to Kalle For This Useful Post:
ReSpawN (05-27-2008)
Old 05-27-2008, 12:57 AM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 05-27-2008 at 02:22 AM. Reason: im an idiot
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
ReSpawN (05-27-2008)
Old 05-27-2008, 09:31 PM   #8 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

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.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:35 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design