Page 1 of 1

String Manipulation and Arrays

Posted: Mon Jun 21, 2010 3:36 pm
by tomnoble
Hi all,

I am still very new to PHP, so I need all the help I can get here. I am looking to do the following:

function tid_value($string1, $string2) //String 1 and String 2 are long strings containing | symbols as a break point between words (like a .csv)
{
Take String 1, and take out each value from it, and place it in an array called "countries".
e.g String1 = "UK|EU|NON EU|US"
Countries=
UK
EU
NON EU
US

And then do the same for string 2 to a "sub_section" array. Both these strings can very in length from one value to 6.

Then for the arrays I want to do the following:

For each item in the Countries array
{
For each item in the sub_section array
{
Take the value of the Countries array being pointed too
Take the value of the sub_section array being pointed too
Concatenate both values together
}
}
}

Does anyone know of a way to do the above? I expect its pretty simple. My biggest headache is splitting the values from the string when a | is read.

Kind Regards

Tom Noble

Re: String Manipulation and Arrays

Posted: Mon Jun 21, 2010 3:46 pm
by AbraCadaver

Code: Select all

explode()
The rest is easy as well assuming that the arrays are the same length, but if they're not, what are the rules? Do you ignore the extras in one string or add them without concatenation or what?