Custom HTML Array Index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Custom HTML Array Index

Post by thomas777neo »

Good Day

I would like to know how to change the html array index from the default value starting at 0 to a custom description.

For example, I have multiple text boxes that look like this

Code: Select all

<input type="text" id="vtl_intf_logicalpath[1]" name="vtl_intf_logicalpath[1]" value="00" size="2" maxlength="2" tabindex="9" class="swifttext" >
When iterating through the submitted results

Code: Select all

foreach ($_REQUEST["vtl_intf_logicalpath"] as $logical_id => $logical_value)
{
	echo "\$logical_id:$logical_id<br>";
	echo "\$logical_value:$logical_value<br>";
} // foreach ($_REQUEST["vtl_intf_logicalpath"] as $logical_id => $logical_value)
It outputs
$logical_id:0
$logical_value:00
$logical_id:1
$logical_value:01
$logical_id:2
$logical_value:02
I would like to change the array index ($logical_id) to another value starting from a custom number instead of 0

I did try this

Code: Select all

<input type="text" id="vtl_intf_logicalpath[1=>1]" name="vtl_intf_logicalpath[1=>1]" value="00" size="2" maxlength="2" tabindex="9" class="swifttext" >
But it still outputs the same results.

I also tried to find some examples on google to no avail. There are many examples of the default array, but not regarding the changing of the index.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Is there a reason for this...? I'm sure using foreach or something, it wouldn't cause a problem.
Then again, I've no idea what you need to change it for.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can name them whatever you wish. It's all arbitrary to PHP.
Post Reply