473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Calling array keys with embedded variables

Hello,

I'm in the middle of modifying a script and I've come across a problem.
I have a form that gets repeated x number of times and each field in
the form gets the name $item_number_ . $business_item_index ._(the
specific field name). These varaibles get reposted to the same page as
$_POST variables, so that the forms save the users settings. What I'm
trying to do is parse through those fields that the user did not set,
and if they are null, to unset them and decrement the counter
($business_item_index) so that one less form gets written to the screen
the next time the user submits.

My problem is that when I parse through them like this:

if ($_POST['item_number_'.$business_item_index.'_title'] == NULL){
unset ($_POST['item_number_'.$business_item_index.'_title']);
$business_item_index --;
}

Php sees that variable key I'm calling as
item_number_ 1_title
even though I defined $business_item_index as a variable and it works
just fine if I decrement or increment it.

Note the white space after "number_". I can't figure out why php is
prepending a space to my integer.

My actual code is alot more complicated than this, because I'm doing a
foreach statement and splitting the $_POST global array into key =
value and then unsetting all the keys that have
item_number_$business_item_index as a substr($key, 0,13), so that all
of the fields for that business item form gets unset. But I think the
above example is sufficient to explain the problem. If you need to see
a more detailed code block I can post it.

Thanks for any assistance.

Oct 19 '05 #1
1 1367
well, not going deep to the cause you could use
trim($business_item_index)
to get rid of first and last spaces if $business_item_index is a string
after all or you could try to convert string to int like this
intval($business_item_index) it should also remove your leading space

Oct 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andy Levy | last post by:
Hi I have a form which contains several fields. One of which is a group of checkboxes that can all be selected, and if they are - all values should be passed as an array. Each checkbox is...
5
by: Phil Powell | last post by:
Here is my array. Plain and simple enumerative array with values being strings. So why does this fail??? print_r(in_array('album', array_keys($boolword))); This produces FALSE or NULL....
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.