String Manipulation and Arrays

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
tomnoble
Forum Commoner
Posts: 28
Joined: Tue Jun 15, 2010 1:18 pm

String Manipulation and Arrays

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: String Manipulation and Arrays

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply