470,815 Members | 1,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Uisng a string varibale with an array

Okay, I am trying to us a varialble with a list of number values as my data
for an array, yet when I do this it doesnt return any values from the array,
i was able to temporarily fix the proble by just doing s normal array setup
in my function, but the problem is I want the ability to have teh array
values to be changed easily in a varibale style config/include file... Here
is the code i am working with...
===================================
VARIABLE.PHP (my config variables)
====================================
<?php

$pid_prefix = "LPPA";

$site_domain = "www.lafayettepoker.com";
######################################
# PAYOUT PERCENTAGE STRUCTURE
######################################
$range1 = ".60, .30, .10";
$range2 = ".50, .30, .12, .06, .02";
$range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
$range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02, .02,
..02, .02, .01, .01, .01, .01, .01";
$range5 = "";
$range6 = "";
######################################
# POINT POOL
######################################
$pool = "5000";
?>
=======================================
MAIN PART OF SCRIPT
=======================================
<?php
require ('variables.php');

if ($tplayer >= 5 && $tplayer <= 10) {
$table = $range1;
}
elseif ($tplayer >= 11 && $tplayer <= 17) {
$table = $range2;
}
elseif ($tplayer >= 18 && $tplayer <= 35) {
$table = $range3;
}
elseif ($tplayer >= 36 && $tplayer <= 65) {
$table = $range4;
}
elseif ($tplayer >= 66 && $tplayer <= 99) {
if ($range5 == '') { $table = "$range4"; }
else { $table = "$range5"; }
}
elseif ($tplayer >= 100) {
if ($range6 == '') { $table = "$range4"; }
else { $table = "$range6"; }
}
else {
$msg = "Not Enough Players";
print_error_msg($msg);
}
calculate_points($table,$rank);


function calculate_points($table,$rank) {
global $pool;
$index = ($rank - 1);
$perc = array($table);
$total_points = $pool * $perc["$index"];
$total_points = round($total_points);
print "$total_points<br>";
}
// PRINT ERROR TO SCREEN
function print_error_msg($msg) {
print "$msg";
}

?>
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
Ive also tried a few differnt variatons of teh above, including formatting
the $range string to look similiar to an array, in other words i addded in
sigle-quotes so the range variables would look like this
$range1 = " '.60', '.30', '.10' "; (note the spaces seperating the double
and single quoute, is just there to show that there are 2 types of quotes
used)

Ok I will test this after i post this since i dont htink it will work
anyway, but looking at the above string, is it possible the reason that
string didnt works is because i didnt escape teh sigle quotes, and if that
is the case how come it doesnt work without teh single quotes at all.. I
really am not sure of what i am doing wrong here...
Apr 5 '06 #1
5 1349
Chris H wrote:
Okay, I am trying to us a varialble with a list of number values as my data
for an array, yet when I do this it doesnt return any values from the array,
i was able to temporarily fix the proble by just doing s normal array setup
in my function, but the problem is I want the ability to have teh array
values to be changed easily in a varibale style config/include file... Here
is the code i am working with...
===================================
VARIABLE.PHP (my config variables)
====================================
<?php

$pid_prefix = "LPPA";

$site_domain = "www.lafayettepoker.com";
######################################
# PAYOUT PERCENTAGE STRUCTURE
######################################
$range1 = ".60, .30, .10";
$range2 = ".50, .30, .12, .06, .02";
$range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
$range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02, .02,
.02, .02, .01, .01, .01, .01, .01";
$range5 = "";
$range6 = "";
######################################
# POINT POOL
######################################
$pool = "5000";
?>
=======================================
MAIN PART OF SCRIPT
=======================================
<?php
require ('variables.php');

if ($tplayer >= 5 && $tplayer <= 10) {
$table = $range1;
}
elseif ($tplayer >= 11 && $tplayer <= 17) {
$table = $range2;
}
elseif ($tplayer >= 18 && $tplayer <= 35) {
$table = $range3;
}
elseif ($tplayer >= 36 && $tplayer <= 65) {
$table = $range4;
}
elseif ($tplayer >= 66 && $tplayer <= 99) {
if ($range5 == '') { $table = "$range4"; }
else { $table = "$range5"; }
}
elseif ($tplayer >= 100) {
if ($range6 == '') { $table = "$range4"; }
else { $table = "$range6"; }
}
else {
$msg = "Not Enough Players";
print_error_msg($msg);
}
calculate_points($table,$rank);


function calculate_points($table,$rank) {
global $pool;
$index = ($rank - 1);
$perc = array($table);
$total_points = $pool * $perc["$index"];
$total_points = round($total_points);
print "$total_points<br>";
}
// PRINT ERROR TO SCREEN
function print_error_msg($msg) {
print "$msg";
}

?>
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
Ive also tried a few differnt variatons of teh above, including formatting
the $range string to look similiar to an array, in other words i addded in
sigle-quotes so the range variables would look like this
$range1 = " '.60', '.30', '.10' "; (note the spaces seperating the double
and single quoute, is just there to show that there are 2 types of quotes
used)

Ok I will test this after i post this since i dont htink it will work
anyway, but looking at the above string, is it possible the reason that
string didnt works is because i didnt escape teh sigle quotes, and if that
is the case how come it doesnt work without teh single quotes at all.. I
really am not sure of what i am doing wrong here...


Either:

$table = array( .60, .30, .10 );
or
$table = explode(', ', ".06, .30, .10");

should work for you.
Apr 5 '06 #2
see the problem is i really need the array values to come from a string
variable, this way the administartor can easily set/modify the payout
percentage "range" witrhin teh variables.php file, so the admin never has to
be in the main parts of my code, i guess i could always just use mySQL and
have the ranges set in a table for the scripts configs. altho i really am
trying to keep from using MySQL so much to relieve any server strain
"David Haynes" <da***********@sympatico.ca> wrote in message
news:GY*******************@fe64.usenetserver.com.. .
Chris H wrote:
Okay, I am trying to us a varialble with a list of number values as my
data for an array, yet when I do this it doesnt return any values from
the array, i was able to temporarily fix the proble by just doing s
normal array setup in my function, but the problem is I want the ability
to have teh array values to be changed easily in a varibale style
config/include file... Here is the code i am working with...
===================================
VARIABLE.PHP (my config variables)
====================================
<?php

$pid_prefix = "LPPA";

$site_domain = "www.lafayettepoker.com";
######################################
# PAYOUT PERCENTAGE STRUCTURE
######################################
$range1 = ".60, .30, .10";
$range2 = ".50, .30, .12, .06, .02";
$range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
$range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02,
.02, .02, .02, .01, .01, .01, .01, .01";
$range5 = "";
$range6 = "";
######################################
# POINT POOL
######################################
$pool = "5000";
?>
=======================================
MAIN PART OF SCRIPT
=======================================
<?php
require ('variables.php');

if ($tplayer >= 5 && $tplayer <= 10) {
$table = $range1;
}
elseif ($tplayer >= 11 && $tplayer <= 17) {
$table = $range2;
}
elseif ($tplayer >= 18 && $tplayer <= 35) {
$table = $range3;
}
elseif ($tplayer >= 36 && $tplayer <= 65) {
$table = $range4;
}
elseif ($tplayer >= 66 && $tplayer <= 99) {
if ($range5 == '') { $table = "$range4"; }
else { $table = "$range5"; }
}
elseif ($tplayer >= 100) {
if ($range6 == '') { $table = "$range4"; }
else { $table = "$range6"; }
}
else {
$msg = "Not Enough Players";
print_error_msg($msg);
}
calculate_points($table,$rank);


function calculate_points($table,$rank) {
global $pool;
$index = ($rank - 1);
$perc = array($table);
$total_points = $pool * $perc["$index"];
$total_points = round($total_points);
print "$total_points<br>";
}
// PRINT ERROR TO SCREEN
function print_error_msg($msg) {
print "$msg";
}

?>
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
Ive also tried a few differnt variatons of teh above, including
formatting the $range string to look similiar to an array, in other words
i addded in sigle-quotes so the range variables would look like this
$range1 = " '.60', '.30', '.10' "; (note the spaces seperating the
double and single quoute, is just there to show that there are 2 types of
quotes used)

Ok I will test this after i post this since i dont htink it will work
anyway, but looking at the above string, is it possible the reason that
string didnt works is because i didnt escape teh sigle quotes, and if
that is the case how come it doesnt work without teh single quotes at
all.. I really am not sure of what i am doing wrong here...


Either:

$table = array( .60, .30, .10 );
or
$table = explode(', ', ".06, .30, .10");

should work for you.

Apr 6 '06 #3
nevermind i figured it out, just have to make the config variables as arrays
instead, i dunno tho for some reason that variation didnt work earlier must
of had syntax error somewhere.

thanks agian for ur help all

"Chris H" <lp******@insightbb.com> wrote in message
news:3HYYf.667749$084.20176@attbi_s22...
see the problem is i really need the array values to come from a string
variable, this way the administartor can easily set/modify the payout
percentage "range" witrhin teh variables.php file, so the admin never has
to be in the main parts of my code, i guess i could always just use mySQL
and have the ranges set in a table for the scripts configs. altho i really
am trying to keep from using MySQL so much to relieve any server strain
"David Haynes" <da***********@sympatico.ca> wrote in message
news:GY*******************@fe64.usenetserver.com.. .
Chris H wrote:
Okay, I am trying to us a varialble with a list of number values as my
data for an array, yet when I do this it doesnt return any values from
the array, i was able to temporarily fix the proble by just doing s
normal array setup in my function, but the problem is I want the ability
to have teh array values to be changed easily in a varibale style
config/include file... Here is the code i am working with...
===================================
VARIABLE.PHP (my config variables)
====================================
<?php

$pid_prefix = "LPPA";

$site_domain = "www.lafayettepoker.com";
######################################
# PAYOUT PERCENTAGE STRUCTURE
######################################
$range1 = ".60, .30, .10";
$range2 = ".50, .30, .12, .06, .02";
$range3 = "'.33, .17, .14, .12, .10, .06, .05, .04, .03, .02";
$range4 = ".25, .15, .10, .08, .07, .05, .05, .04, .03, .03, .02, .02,
.02, .02, .02, .01, .01, .01, .01, .01";
$range5 = "";
$range6 = "";
######################################
# POINT POOL
######################################
$pool = "5000";
?>
=======================================
MAIN PART OF SCRIPT
=======================================
<?php
require ('variables.php');

if ($tplayer >= 5 && $tplayer <= 10) {
$table = $range1;
}
elseif ($tplayer >= 11 && $tplayer <= 17) {
$table = $range2;
}
elseif ($tplayer >= 18 && $tplayer <= 35) {
$table = $range3;
}
elseif ($tplayer >= 36 && $tplayer <= 65) {
$table = $range4;
}
elseif ($tplayer >= 66 && $tplayer <= 99) {
if ($range5 == '') { $table = "$range4"; }
else { $table = "$range5"; }
}
elseif ($tplayer >= 100) {
if ($range6 == '') { $table = "$range4"; }
else { $table = "$range6"; }
}
else {
$msg = "Not Enough Players";
print_error_msg($msg);
}
calculate_points($table,$rank);


function calculate_points($table,$rank) {
global $pool;
$index = ($rank - 1);
$perc = array($table);
$total_points = $pool * $perc["$index"];
$total_points = round($total_points);
print "$total_points<br>";
}
// PRINT ERROR TO SCREEN
function print_error_msg($msg) {
print "$msg";
}

?>
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
Ive also tried a few differnt variatons of teh above, including
formatting the $range string to look similiar to an array, in other
words i addded in sigle-quotes so the range variables would look like
this
$range1 = " '.60', '.30', '.10' "; (note the spaces seperating the
double and single quoute, is just there to show that there are 2 types
of quotes used)

Ok I will test this after i post this since i dont htink it will work
anyway, but looking at the above string, is it possible the reason that
string didnt works is because i didnt escape teh sigle quotes, and if
that is the case how come it doesnt work without teh single quotes at
all.. I really am not sure of what i am doing wrong here...


Either:

$table = array( .60, .30, .10 );
or
$table = explode(', ', ".06, .30, .10");

should work for you.


Apr 6 '06 #4
Chris H wrote:
see the problem is i really need the array values to come from a string
variable, this way the administartor can easily set/modify the payout
percentage "range" witrhin teh variables.php file, so the admin never has to
be in the main parts of my code, i guess i could always just use mySQL and
have the ranges set in a table for the scripts configs. altho i really am
trying to keep from using MySQL so much to relieve any server strain

See that string in the explode function?
What's wrong with that?

How about this for clarity?

<?php
include_once('variables.php');

$table = explode(',', $range1);
printf("The first value is %f\n", $table[0]);
printf("The second value is %f\n", $table[0]);
?>

[variables.php]
$range1 = "0.60, 0.41, 0.20";

Apr 6 '06 #5
David Haynes wrote:
Chris H wrote:
see the problem is i really need the array values to come from a
string variable, this way the administartor can easily set/modify the
payout percentage "range" witrhin teh variables.php file, so the admin
never has to be in the main parts of my code, i guess i could always
just use mySQL and have the ranges set in a table for the scripts
configs. altho i really am trying to keep from using MySQL so much to
relieve any server strain

See that string in the explode function?
What's wrong with that?

How about this for clarity?

<?php
include_once('variables.php');

$table = explode(',', $range1);
printf("The first value is %f\n", $table[0]);
printf("The second value is %f\n", $table[0]);

correction: should be $table[1] ?>

[variables.php]
$range1 = "0.60, 0.41, 0.20";


Apr 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Kiran Kumar | last post: by
7 posts views Thread by al | last post: by
3 posts views Thread by aroraamit81 | last post: by
2 posts views Thread by rachit.goyal | last post: by
8 posts views Thread by pkirk25 | last post: by
1 post views Thread by Josuan | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.