PHP Array
Moderator: General Moderators
Code: Select all
$VariableName = array(
'1' => 'String Text',
'2' => 'String Text',
'3' => 'String Text',
'4' => 'String Text',
'5' => 'String Text'
);- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: PHP Array
If you really want to start it at 1 instead of zero, just add a comma to the beginning of your list like this:quadoc wrote:I've the following string $st = "1,5,3,2" and I want to put the value into an array $a like
a[1] = "1"
a[2] = "5"
a[3] = "3"
a[4] = "2"
How do I do that? Could someone posts some tips. Thanks...
Code: Select all
$st = "1,5,3,2"; // your original
$st = ",1,5,3,2"; // added extra comma
$a = explode(",",$st);
unset($a[0]);just a little fyi, in case you didn't know.
Code: Select all
$bob[] = "hello"; // saves to $bob[0]
$bob[] = "yellow"; // saves to $bob[1] and so on...