[200] PHP create array

Status
Not open for further replies.

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
I want to be able to update an array

PHP:
/* Plan Options */            // 'Plan Name' => 'Plan ID'
$planOptions = array( 'Unlimited (5/month)'     => '1',
                      'Unlimited (50/year)'     => '2',
                      '500 texts (1/month)'     => '3',
                      '1500 texts (2/month)'    => '4',
                      '4000 texts (3/month)'    => '5',
                      '7000 texts (4/month)'    => '6'     // do NOT end the last one with a comma(,)
                    );
and it places the array in a database, and when the user updates the database to add in a new plan, I also want it to update the configuration files.

I'm thinking like fopen(), look for the end of $planOptions, insert the comma for the previous ending, then add in the new one(s), and don't insert the comma for the finishing one


I am offering 200 credits to whoever can solve this for me
 
Last edited:

tttony

Member
Messages
147
Reaction score
0
Points
16
do you need save the array content in a file??

why not get the data from database and save into array and then works with that array??

something like this:

PHP:
<?php

$sql = "SELECT * FROM plan_table ORDER BY plan_id";
$rs = mysql_query($sql);

$planOptions = array();

while($row = mysql_fetch_assoc($rs)) 
{

//          'Plan Name'   =>    'Plan ID'
$planOptions[$row['plan_name']] = $row['plan_id'];

}

// the array will look like this

/* Plan Options */            // 'Plan Name' => 'Plan ID'
$planOptions = array( 'Unlimited (5/month)'     => '1',
                      'Unlimited (50/year)'     => '2',
                      '500 texts (1/month)'     => '3',
                      '1500 texts (2/month)'    => '4',
                      '4000 texts (3/month)'    => '5',
                      '7000 texts (4/month)'    => '6'     // do NOT end the last one with a comma(,)
                    );  

?>
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
or. store them in an SQL db.

with a backend to update it

and use

PHP:
$planOptions = explode(/*get the plans from the db*/);
 

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
actually guys, I am going a whole different route, so I don't need this any more
thank you though!
 
Status
Not open for further replies.
Top